add delete contact functionality for desktop

This commit is contained in:
julian 2022-11-18 09:07:31 -06:00
parent 17e4976a89
commit aa966a106d
2 changed files with 260 additions and 135 deletions

View file

@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/models/contact.dart';
import 'package:stackwallet/models/paymint/transactions_model.dart';
import 'package:stackwallet/notifications/show_flush_bar.dart';
import 'package:stackwallet/pages/address_book_views/subviews/add_new_contact_address_view.dart';
import 'package:stackwallet/pages_desktop_specific/home/address_book_view/subwidgets/desktop_address_card.dart';
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
@ -15,6 +16,8 @@ import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog.dart';
import 'package:stackwallet/widgets/desktop/desktop_dialog_close_button.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
@ -74,8 +77,16 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
@override
Widget build(BuildContext context) {
final contact = ref.watch(addressBookServiceProvider
// provider hack to prevent trying to update widget with deleted contact
Contact? _contact;
try {
_contact = ref.watch(addressBookServiceProvider
.select((value) => value.getContactById(widget.contactId)));
} catch (_) {
return Container();
}
final contact = _contact!;
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
@ -129,6 +140,7 @@ class _DesktopContactDetailsState extends ConsumerState<DesktopContactDetails> {
),
],
),
if (widget.contactId != "default")
SecondaryButton(
label: "Options",
width: 96,
@ -453,9 +465,11 @@ class _DesktopContactOptionsMenuPopupState
),
),
),
if (widget.contactId != "default")
const SizedBox(
height: 2,
),
if (widget.contactId != "default")
MouseRegion(
onEnter: (_) {
setState(() {
@ -516,9 +530,11 @@ class _DesktopContactOptionsMenuPopupState
),
),
),
if (widget.contactId != "default")
const SizedBox(
height: 2,
),
if (widget.contactId != "default")
MouseRegion(
onEnter: (_) {
setState(() {
@ -540,7 +556,109 @@ class _DesktopContactOptionsMenuPopupState
),
),
onPressed: () {
print("should delete contact");
final contact = ref
.read(addressBookServiceProvider)
.getContactById(widget.contactId);
// pop context menu
Navigator.of(context).pop();
showDialog<dynamic>(
context: context,
useSafeArea: true,
barrierDismissible: true,
builder: (_) => DesktopDialog(
maxWidth: 500,
maxHeight: 300,
child: Column(
children: [
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(
left: 32,
),
child: Text(
"Delete ${contact.name}?",
style: STextStyles.desktopH3(context),
),
),
const DesktopDialogCloseButton(),
],
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 32,
right: 32,
bottom: 32,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Spacer(
flex: 1,
),
Text(
"Contact will be deleted permanently!",
style: STextStyles.desktopTextSmall(
context),
),
const Spacer(
flex: 2,
),
Row(
children: [
Expanded(
child: SecondaryButton(
label: "Cancel",
onPressed:
Navigator.of(context).pop,
buttonHeight: ButtonHeight.l,
),
),
const SizedBox(
width: 16,
),
Expanded(
child: Consumer(
builder: (context, ref, __) =>
PrimaryButton(
label: "Delete",
buttonHeight:
ButtonHeight.l,
onPressed: () {
ref
.read(
addressBookServiceProvider)
.removeContact(
contact.id);
Navigator.of(context)
.pop();
showFloatingFlushBar(
type: FlushBarType
.success,
message:
"${contact.name} deleted",
context: context,
);
},
),
),
),
],
)
],
),
),
),
],
),
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/models/contact.dart';
import 'package:stackwallet/pages/address_book_views/subviews/contact_popup.dart';
import 'package:stackwallet/providers/global/address_book_service_provider.dart';
import 'package:stackwallet/utilities/assets.dart';
@ -44,10 +45,16 @@ class _AddressBookCardState extends ConsumerState<AddressBookCard> {
@override
Widget build(BuildContext context) {
// final isTiny = SizingUtilities.isTinyWidth(context);
final contact = ref.watch(addressBookServiceProvider
// provider hack to prevent trying to update widget with deleted contact
Contact? _contact;
try {
_contact = ref.watch(addressBookServiceProvider
.select((value) => value.getContactById(contactId)));
} catch (_) {
return Container();
}
final contact = _contact!;
final List<Coin> coins = [];
for (var element in contact.addresses) {