Fix edit/delete option slidable (#561)

* Fix Edit Slidable in receive address cell Fix Edit/Delete slidable in contact list * Update Delete node slidable

Omar Hatem committed Oct 24, 2022 at 21:15 UTC 12e54426bd42da720994dc8d61150492047215d4
3 files changed +109 -88
lib/src/screens/contact/contact_list_page.dart
+44 -37
@@ -1,4 +1,5 @@
1 import 'package:cake_wallet/entities/contact_base.dart';
2 +import 'package:cake_wallet/entities/contact_record.dart';
3 import 'package:cake_wallet/utils/show_bar.dart';
4 import 'package:cake_wallet/utils/show_pop_up.dart';
5 import 'package:flutter/material.dart';
@@ -34,12 +35,12 @@ class ContactListPage extends BasePage {
35 height: 32.0,
36 decoration: BoxDecoration(
37 shape: BoxShape.circle,
37 - color: Theme.of(context).accentTextTheme!.caption!.color!),
38 + color: Theme.of(context).accentTextTheme.caption!.color!),
39 child: Stack(
40 alignment: Alignment.center,
41 children: <Widget>[
42 Icon(Icons.add,
42 - color: Theme.of(context).primaryTextTheme!.headline6!.color!,
43 + color: Theme.of(context).primaryTextTheme.headline6!.color!,
44 size: 22.0),
45 ButtonTheme(
46 minWidth: 32.0,
@@ -66,9 +67,9 @@ class ContactListPage extends BasePage {
67 return CollapsibleSectionList(
68 context: context,
69 sectionCount: 2,
69 - themeColor: Theme.of(context).primaryTextTheme!.headline6!.color!,
70 + themeColor: Theme.of(context).primaryTextTheme.headline6!.color!,
71 dividerThemeColor:
71 - Theme.of(context).primaryTextTheme!.caption!.decorationColor!,
72 + Theme.of(context).primaryTextTheme.caption!.decorationColor!,
73 sectionTitleBuilder: (_, int sectionIndex) {
74 var title = 'Contacts';
75
@@ -91,37 +92,13 @@ class ContactListPage extends BasePage {
92
93 final contact = contactListViewModel.contacts[index];
94 final content = generateRaw(context, contact);
94 - // FIX-ME: Slidable
95 - return content;
96 - // return !isEditable
97 - // ? content
98 - // : Slidable(
99 - // key: Key('${contact.key}'),
100 - // actionPane: SlidableDrawerActionPane(),
101 - // child: content,
102 - // secondaryActions: <Widget>[
103 - // IconSlideAction(
104 - // caption: S.of(context).edit,
105 - // color: Colors.blue,
106 - // icon: Icons.edit,
107 - // onTap: () async => await Navigator.of(context)
108 - // .pushNamed(Routes.addressBookAddContact,
109 - // arguments: contact),
110 - // ),
111 - // IconSlideAction(
112 - // caption: S.of(context).delete,
113 - // color: Colors.red,
114 - // icon: CupertinoIcons.delete,
115 - // onTap: () async {
116 - // final isDelete =
117 - // await showAlertDialog(context) ?? false;
118 -
119 - // if (isDelete) {
120 - // await contactListViewModel.delete(contact);
121 - // }
122 - // },
123 - // ),
124 - // ]);
95 + return !isEditable
96 + ? content
97 + : Slidable(
98 + key: Key('${contact.key}'),
99 + endActionPane: _actionPane(context, contact),
100 + child: content,
101 + );
102 },
103 );
104 },
@@ -141,7 +118,7 @@ class ContactListPage extends BasePage {
118 final isCopied = await showNameAndAddressDialog(
119 context, contact.name, contact.address);
120
144 - if (isCopied != null && isCopied) {
121 + if (isCopied) {
122 await Clipboard.setData(ClipboardData(text: contact.address));
123 await showBar<void>(context, S.of(context).copied_to_clipboard);
124 }
@@ -165,7 +142,7 @@ class ContactListPage extends BasePage {
142 style: TextStyle(
143 fontSize: 14,
144 fontWeight: FontWeight.normal,
168 - color: Theme.of(context).primaryTextTheme!.headline6!.color!),
145 + color: Theme.of(context).primaryTextTheme.headline6!.color!),
146 ),
147 )
148 )
@@ -266,4 +243,34 @@ class ContactListPage extends BasePage {
243 actionLeftButton: () => Navigator.of(context).pop(false));
244 }) ?? false;
245 }
246 +
247 + ActionPane _actionPane(BuildContext context, ContactRecord contact) => ActionPane(
248 + motion: const ScrollMotion(),
249 + extentRatio: 0.4,
250 + children: [
251 + SlidableAction(
252 + onPressed: (_) async => await Navigator.of(context)
253 + .pushNamed(Routes.addressBookAddContact,
254 + arguments: contact),
255 + backgroundColor: Colors.blue,
256 + foregroundColor: Colors.white,
257 + icon: Icons.edit,
258 + label: S.of(context).edit,
259 + ),
260 + SlidableAction(
261 + onPressed: (_) async {
262 + final isDelete =
263 + await showAlertDialog(context);
264 +
265 + if (isDelete) {
266 + await contactListViewModel.delete(contact);
267 + }
268 + },
269 + backgroundColor: Colors.red,
270 + foregroundColor: Colors.white,
271 + icon: CupertinoIcons.delete,
272 + label: S.of(context).delete,
273 + ),
274 + ],
275 + );
276 }
lib/src/screens/nodes/nodes_list_page.dart
+44 -36
@@ -1,4 +1,5 @@
1 import 'package:cake_wallet/utils/show_pop_up.dart';
2 +import 'package:cw_core/node.dart';
3 import 'package:flutter/material.dart';
4 import 'package:flutter/cupertino.dart';
5 import 'package:flutter_mobx/flutter_mobx.dart';
@@ -26,7 +27,7 @@ class NodeListPage extends BasePage {
27 height: 32,
28 decoration: BoxDecoration(
29 borderRadius: BorderRadius.all(Radius.circular(16)),
29 - color: Theme.of(context).accentTextTheme!.caption!.color!),
30 + color: Theme.of(context).accentTextTheme.caption!.color!),
31 child: ButtonTheme(
32 minWidth: double.minPositive,
33 child: TextButton(
@@ -85,7 +86,7 @@ class NodeListPage extends BasePage {
86
87 final node = nodeListViewModel.nodes[index];
88 final isSelected =
88 - node.keyIndex == nodeListViewModel.currentNode?.keyIndex;
89 + node.keyIndex == nodeListViewModel.currentNode.keyIndex;
90 final nodeListRow = NodeListRow(
91 title: node.uriRaw,
92 isSelected: isSelected,
@@ -114,45 +115,52 @@ class NodeListPage extends BasePage {
115 });
116 });
117 });
117 - // FIX-ME: Slidable
118 - // final dismissibleRow = Slidable(
119 - // key: Key('${node.keyIndex}'),
120 - // actionPane: SlidableDrawerActionPane(),
121 - // child: nodeListRow,
122 - // secondaryActions: <Widget>[
123 - // IconSlideAction(
124 - // caption: S.of(context).delete,
125 - // color: Colors.red,
126 - // icon: CupertinoIcons.delete,
127 - // onTap: () async {
128 - // final confirmed = await showPopUp<bool>(
129 - // context: context,
130 - // builder: (BuildContext context) {
131 - // return AlertWithTwoActions(
132 - // alertTitle: S.of(context).remove_node,
133 - // alertContent:
134 - // S.of(context).remove_node_message,
135 - // rightButtonText: S.of(context).remove,
136 - // leftButtonText: S.of(context).cancel,
137 - // actionRightButton: () =>
138 - // Navigator.pop(context, true),
139 - // actionLeftButton: () =>
140 - // Navigator.pop(context, false));
141 - // }) ??
142 - // false;
118
144 - // if (confirmed) {
145 - // await nodeListViewModel.delete(node);
146 - // }
147 - // },
148 - // ),
149 - // ]);
119 + final dismissibleRow = Slidable(
120 + key: Key('${node.keyIndex}'),
121 + startActionPane: _actionPane(context, node),
122 + endActionPane: _actionPane(context, node),
123 + child: nodeListRow,
124 + );
125
151 - return nodeListRow;
152 - // return isSelected ? nodeListRow : dismissibleRow;
126 + return isSelected ? nodeListRow : dismissibleRow;
127 });
128 },
129 ),
130 );
131 }
132 +
133 + ActionPane _actionPane(BuildContext context, Node node) => ActionPane(
134 + motion: const ScrollMotion(),
135 + extentRatio: 0.3,
136 + children: [
137 + SlidableAction(
138 + onPressed: (context) async {
139 + final confirmed = await showPopUp<bool>(
140 + context: context,
141 + builder: (BuildContext context) {
142 + return AlertWithTwoActions(
143 + alertTitle: S.of(context).remove_node,
144 + alertContent:
145 + S.of(context).remove_node_message,
146 + rightButtonText: S.of(context).remove,
147 + leftButtonText: S.of(context).cancel,
148 + actionRightButton: () =>
149 + Navigator.pop(context, true),
150 + actionLeftButton: () =>
151 + Navigator.pop(context, false));
152 + }) ??
153 + false;
154 +
155 + if (confirmed) {
156 + await nodeListViewModel.delete(node);
157 + }
158 + },
159 + backgroundColor: Colors.red,
160 + foregroundColor: Colors.white,
161 + icon: CupertinoIcons.delete,
162 + label: S.of(context).delete,
163 + ),
164 + ],
165 + );
166 }
lib/src/screens/receive/widgets/address_cell.dart
+21 -15
@@ -57,6 +57,7 @@ class AddressCell extends StatelessWidget {
57 final Widget cell = InkWell(
58 onTap: () => onTap?.call(address),
59 child: Container(
60 + width: double.infinity,
61 color: backgroundColor,
62 padding: EdgeInsets.only(left: 24, right: 24, top: 28, bottom: 28),
63 child: Text(
@@ -69,20 +70,25 @@ class AddressCell extends StatelessWidget {
70 ),
71 ),
72 ));
72 - // FIX-ME: Slidable
73 - return cell;
74 - // return Container(
75 - // color: backgroundColor,
76 - // child: Slidable(
77 - // key: Key(address),
78 - // actionPane: SlidableDrawerActionPane(),
79 - // child: cell,
80 - // secondaryActions: <Widget>[
81 - // IconSlideAction(
82 - // caption: S.of(context).edit,
83 - // color: Colors.blue,
84 - // icon: Icons.edit,
85 - // onTap: () => onEdit?.call())
86 - // ]));
73 + return Slidable(
74 + key: Key(address),
75 + startActionPane: _actionPane(context),
76 + endActionPane: _actionPane(context),
77 + child: cell,
78 + );
79 }
80 +
81 + ActionPane _actionPane(BuildContext context) => ActionPane(
82 + motion: const ScrollMotion(),
83 + extentRatio: 0.3,
84 + children: [
85 + SlidableAction(
86 + onPressed: (_) => onEdit?.call(),
87 + backgroundColor: Colors.blue,
88 + foregroundColor: Colors.white,
89 + icon: Icons.edit,
90 + label: S.of(context).edit,
91 + ),
92 + ],
93 + );
94 }