@@ -16,6 +16,7 @@ import 'package:stackwallet/utilities/constants.dart';
1616import 'package:stackwallet/utilities/text_styles.dart' ;
1717import 'package:stackwallet/utilities/theme/stack_colors.dart' ;
1818import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart' ;
19+ import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart' ;
1920import 'package:stackwallet/widgets/emoji_select_sheet.dart' ;
2021import 'package:stackwallet/widgets/icon_widgets/x_icon.dart' ;
2122import 'package:stackwallet/widgets/stack_text_field.dart' ;
@@ -73,10 +74,23 @@ class _AddAddressBookEntryViewState
7374 }
7475
7576 List <NewContactAddressEntryForm > forms = [];
76- int _formCount = 0 ;
77+ final Set <int > _formIds = {};
78+
79+ void _removeForm (int id) {
80+ forms.retainWhere ((e) => e.id != id);
81+ _formIds.remove (id);
82+ ref.refresh (addressEntryDataProvider (id));
83+ setState (() {});
84+ }
7785
7886 void _addForm () {
79- int id = ++ _formCount;
87+ int id = 0 ;
88+ // ensure unique form id while allowing reuse of removed form ids
89+ while (_formIds.contains (id)) {
90+ id++ ;
91+ }
92+ _formIds.add (id);
93+
8094 forms.add (
8195 NewContactAddressEntryForm (
8296 key: Key ("contactAddressEntryForm_$id " ),
@@ -303,22 +317,34 @@ class _AddAddressBookEntryViewState
303317 },
304318 ),
305319 ),
306- if (_formCount <= 1 )
320+ if (forms.length <= 1 )
307321 const SizedBox (
308322 height: 8 ,
309323 ),
310- if (_formCount <= 1 ) forms[0 ],
311- if (_formCount > 1 )
312- for (int i = 0 ; i < _formCount ; i++ )
324+ if (forms.length <= 1 ) forms[0 ],
325+ if (forms.length > 1 )
326+ for (int i = 0 ; i < forms.length ; i++ )
313327 Column (
314328 crossAxisAlignment: CrossAxisAlignment .start,
315329 children: [
316330 const SizedBox (
317331 height: 12 ,
318332 ),
319- Text (
320- "Address ${i + 1 }" ,
321- style: STextStyles .smallMed12 (context),
333+ Row (
334+ mainAxisAlignment:
335+ MainAxisAlignment .spaceBetween,
336+ children: [
337+ Text (
338+ "Address ${i + 1 }" ,
339+ style: STextStyles .smallMed12 (context),
340+ ),
341+ BlueTextButton (
342+ onTap: () {
343+ _removeForm (forms[i].id);
344+ },
345+ text: "Remove" ,
346+ ),
347+ ],
322348 ),
323349 const SizedBox (
324350 height: 8 ,
@@ -329,7 +355,7 @@ class _AddAddressBookEntryViewState
329355 const SizedBox (
330356 height: 16 ,
331357 ),
332- GestureDetector (
358+ BlueTextButton (
333359 onTap: () {
334360 _addForm ();
335361 scrollController.animateTo (
@@ -338,11 +364,15 @@ class _AddAddressBookEntryViewState
338364 curve: Curves .easeInOut,
339365 );
340366 },
341- child: Text (
342- "+ Add another address" ,
343- style: STextStyles .largeMedium14 (context),
344- ),
367+ text: "+ Add another address" ,
345368 ),
369+ // GestureDetector(
370+ //
371+ // child: Text(
372+ // "+ Add another address",
373+ // style: STextStyles.largeMedium14(context),
374+ // ),
375+ // ),
346376 const SizedBox (
347377 height: 16 ,
348378 ),
@@ -411,10 +441,12 @@ class _AddAddressBookEntryViewState
411441 }
412442 List <ContactAddressEntry > entries =
413443 [];
414- for (int i = 0 ; i < _formCount; i++ ) {
444+ for (int i = 0 ;
445+ i < forms.length;
446+ i++ ) {
415447 entries.add (ref
416448 .read (addressEntryDataProvider (
417- i + 1 ))
449+ forms[i].id ))
418450 .buildAddressEntry ());
419451 }
420452 Contact contact = Contact (
@@ -438,7 +470,15 @@ class _AddAddressBookEntryViewState
438470 : null ,
439471 child: Text (
440472 "Save" ,
441- style: STextStyles .button (context),
473+ style: STextStyles .button (context).copyWith (
474+ color: shouldEnableSave
475+ ? Theme .of (context)
476+ .extension < StackColors > ()!
477+ .buttonTextPrimary
478+ : Theme .of (context)
479+ .extension < StackColors > ()!
480+ .buttonTextPrimaryDisabled,
481+ ),
442482 ),
443483 );
444484 },
0 commit comments