mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 09:47:37 +00:00
address label save fix
This commit is contained in:
parent
456abf7ee4
commit
c7bcabf328
4 changed files with 24 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/exceptions/main_db/main_db_exception.dart';
|
||||
import 'package:stackwallet/exceptions/sw_exception.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/utilities/stack_file_system.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
@ -236,10 +235,6 @@ class MainDB {
|
|||
Future<int> updateAddressLabel(AddressLabel addressLabel) async {
|
||||
try {
|
||||
return await isar.writeTxn(() async {
|
||||
final deleted = await isar.addresses.delete(addressLabel.id);
|
||||
if (!deleted) {
|
||||
throw SWException("Failed to delete $addressLabel before updating");
|
||||
}
|
||||
return await isar.addressLabels.put(addressLabel);
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
|
@ -84,7 +84,7 @@ class _AddressCardState extends State<AddressCard> {
|
|||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
EditAddressLabelView.routeName,
|
||||
arguments: label!,
|
||||
arguments: label!.id,
|
||||
);
|
||||
},
|
||||
),
|
||||
|
@ -122,6 +122,7 @@ class _AddressCardState extends State<AddressCard> {
|
|||
text: widget.address.value,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
unawaited(
|
||||
showFloatingFlushBar(
|
||||
type: FlushBarType.info,
|
||||
|
@ -129,6 +130,7 @@ class _AddressCardState extends State<AddressCard> {
|
|||
context: context,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/db/main_db.dart';
|
||||
import 'package:stackwallet/models/isar/models/address_label.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
|
@ -18,12 +19,12 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
|||
class EditAddressLabelView extends ConsumerStatefulWidget {
|
||||
const EditAddressLabelView({
|
||||
Key? key,
|
||||
required this.addressLabel,
|
||||
required this.addressLabelId,
|
||||
}) : super(key: key);
|
||||
|
||||
static const String routeName = "/editAddressLabel";
|
||||
|
||||
final AddressLabel addressLabel;
|
||||
final int addressLabelId;
|
||||
|
||||
@override
|
||||
ConsumerState<EditAddressLabelView> createState() =>
|
||||
|
@ -36,11 +37,17 @@ class _EditAddressLabelViewState extends ConsumerState<EditAddressLabelView> {
|
|||
|
||||
late final bool isDesktop;
|
||||
|
||||
late AddressLabel addressLabel;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
isDesktop = Util.isDesktop;
|
||||
_labelFieldController = TextEditingController();
|
||||
_labelFieldController.text = widget.addressLabel.value;
|
||||
addressLabel = MainDB.instance.isar.addressLabels
|
||||
.where()
|
||||
.idEqualTo(widget.addressLabelId)
|
||||
.findFirstSync()!;
|
||||
_labelFieldController.text = addressLabel.value;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
@ -195,7 +202,7 @@ class _EditAddressLabelViewState extends ConsumerState<EditAddressLabelView> {
|
|||
label: "Save",
|
||||
onPressed: () async {
|
||||
await MainDB.instance.updateAddressLabel(
|
||||
widget.addressLabel.copyWith(
|
||||
addressLabel.copyWith(
|
||||
label: _labelFieldController.text,
|
||||
),
|
||||
);
|
||||
|
@ -209,7 +216,7 @@ class _EditAddressLabelViewState extends ConsumerState<EditAddressLabelView> {
|
|||
TextButton(
|
||||
onPressed: () async {
|
||||
await MainDB.instance.updateAddressLabel(
|
||||
widget.addressLabel.copyWith(
|
||||
addressLabel.copyWith(
|
||||
label: _labelFieldController.text,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -489,11 +489,11 @@ class RouteGenerator {
|
|||
return _routeError("${settings.name} invalid args: ${args.toString()}");
|
||||
|
||||
case EditAddressLabelView.routeName:
|
||||
if (args is AddressLabel) {
|
||||
if (args is int) {
|
||||
return getRoute(
|
||||
shouldUseMaterialRoute: useMaterialPageRoute,
|
||||
builder: (_) => EditAddressLabelView(
|
||||
addressLabel: args,
|
||||
addressLabelId: args,
|
||||
),
|
||||
settings: RouteSettings(
|
||||
name: settings.name,
|
||||
|
|
Loading…
Reference in a new issue