address label save fix

This commit is contained in:
julian 2023-03-06 13:27:04 -06:00
parent 456abf7ee4
commit c7bcabf328
4 changed files with 24 additions and 20 deletions

View file

@ -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) {

View file

@ -84,7 +84,7 @@ class _AddressCardState extends State<AddressCard> {
onTap: () {
Navigator.of(context).pushNamed(
EditAddressLabelView.routeName,
arguments: label!,
arguments: label!.id,
);
},
),
@ -122,13 +122,15 @@ class _AddressCardState extends State<AddressCard> {
text: widget.address.value,
),
);
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
if (mounted) {
unawaited(
showFloatingFlushBar(
type: FlushBarType.info,
message: "Copied to clipboard",
context: context,
),
);
}
},
),
),

View file

@ -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,
),
);

View file

@ -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,