From 92e1c3a4c16a2c96aa31404cb24493eeabbc14d6 Mon Sep 17 00:00:00 2001 From: Serhii Date: Fri, 22 Sep 2023 14:09:01 +0300 Subject: [PATCH] refactore send card --- lib/src/screens/send/send_page.dart | 48 +++--- lib/src/screens/send/widgets/send_card.dart | 157 ++++++++++---------- 2 files changed, 98 insertions(+), 107 deletions(-) diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 33928a337..707b248ce 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -258,33 +258,8 @@ class SendPage extends BasePage { } }, onRemove: () { - showPopUp( - context: context, - builder: (dialogContext) { - return AlertWithTwoActions( - alertTitle: - S.of(context).template, - alertContent: S - .of(context) - .confirm_delete_template, - rightButtonText: - S.of(context).delete, - leftButtonText: - S.of(context).cancel, - actionRightButton: () { - Navigator.of(dialogContext) - .pop(); - sendViewModel - .sendTemplateViewModel - .removeTemplate( - template: template); - }, - actionLeftButton: () => - Navigator.of(dialogContext) - .pop()); - }, - ); - }, + showDeleteTemplateAlert(context, template, sendViewModel); + }, ); }, ), @@ -505,6 +480,25 @@ class SendPage extends BasePage { }); } + void showDeleteTemplateAlert(BuildContext context, Template template, SendViewModel sendViewModel) { + showPopUp( + context: context, + builder: (dialogContext) { + return AlertWithTwoActions( + alertTitle: S.of(context).template, + alertContent: S.of(context).confirm_delete_template, + rightButtonText: S.of(context).delete, + leftButtonText: S.of(context).cancel, + actionRightButton: () { + Navigator.of(dialogContext).pop(); + sendViewModel.sendTemplateViewModel.removeTemplate(template: template); + }, + actionLeftButton: () => Navigator.of(dialogContext).pop(), + ); + }, + ); + } + void presentCurrencyPicker(BuildContext context) async { await showPopUp( builder: (_) => Picker( diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index 622c1d7f3..d2d01392e 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -102,12 +102,11 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin _updateHeight()); + WidgetsBinding.instance!.addPostFrameCallback((_) => _updateGenericHeight( + containerKey: _containerKey, + dynamicElementKey: _dynamicElementKey, + additionalPadding: parsedAddressTopPadding, + )); final validator = output.isParsedAddress ? sendViewModel.textValidator : sendViewModel.addressValidator; @@ -192,13 +195,9 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()!.textFieldButtonColor, borderColor: Theme.of(context).extension()!.textFieldBorderColor, - textStyle: TextStyle( - fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white), - hintStyle: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w500, - color: - Theme.of(context).extension()!.textFieldHintColor), + textStyle: genericTextStyle(fontWeight: FontWeight.w500), + hintStyle: genericTextStyle(fontWeight: FontWeight.w500, + color: Theme.of(context).extension()!.textFieldHintColor), onPushPasteButton: (context) async { output.resetParsedAddress(); await output.fetchParsedAddress(context); @@ -223,8 +222,7 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()! .textFieldBorderColor, - textStyle: TextStyle( - fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white), + textStyle: genericTextStyle(fontWeight: FontWeight.w500), validator: sendViewModel.addressValidator)), Observer( builder: (_) => Padding( @@ -255,10 +253,7 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin()! .textFieldButtonIconColor), @@ -304,10 +295,7 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin()! - .textFieldHintColor, - fontWeight: FontWeight.w500, - fontSize: 14), + .textFieldHintColor), validator: output.sendAll ? sendViewModel.allAmountValidator : sendViewModel.amountValidator, @@ -365,9 +349,8 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()! .textFieldButtonIconColor, @@ -397,9 +380,8 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()! .textFieldHintColor), @@ -407,9 +389,8 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()! .textFieldHintColor), @@ -435,23 +416,16 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()!.textFieldBorderColor, - textStyle: TextStyle( - fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white), - placeholderTextStyle: TextStyle( + textStyle: genericTextStyle(fontWeight: FontWeight.w500), + placeholderTextStyle: genericTextStyle(fontWeight: FontWeight.w500, color: - Theme.of(context).extension()!.textFieldHintColor, - fontWeight: FontWeight.w500, - fontSize: 14), + Theme.of(context).extension()!.textFieldHintColor), ), ), Padding( @@ -462,11 +436,9 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin()!.textFieldBorderColor, - textStyle: TextStyle( - fontSize: 14, fontWeight: FontWeight.w500, color: Colors.white), + textStyle: genericTextStyle(fontWeight: FontWeight.w500), hintText: S.of(context).note_optional, - placeholderTextStyle: TextStyle( - fontSize: 14, + placeholderTextStyle: genericTextStyle( fontWeight: FontWeight.w500, color: Theme.of(context).extension()!.textFieldHintColor), @@ -483,8 +455,8 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin[ Text( S.of(context).send_estimated_fee, - style: TextStyle( - fontSize: 12, fontWeight: FontWeight.w500, color: Colors.white), + style: genericTextStyle( + fontSize: 12, fontWeight: FontWeight.w500), ), Container( child: Row( @@ -498,11 +470,7 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin()! .textFieldHintColor, @@ -551,10 +518,7 @@ class SendCardState extends State with AutomaticKeepAliveClientMixin with AutomaticKeepAliveClientMixin( + context: context, + builder: (BuildContext context) { + return AlertWithOneAction( + alertTitle: S.of(context).error, + alertContent: S.of(context).unmatched_currencies, + buttonText: S.of(context).ok, + buttonAction: () => Navigator.of(context).pop()); + }); + } + } + + void _updateGenericHeight({ + required GlobalKey containerKey, + required GlobalKey dynamicElementKey, + double additionalPadding = 0.0, + }) { if (mounted) { - final RenderBox containerBox = _containerKey.currentContext!.findRenderObject() as RenderBox; - final RenderBox dynamicElementBox = _dynamicElementKey.currentContext!.findRenderObject() as RenderBox; + final RenderBox containerBox = containerKey.currentContext!.findRenderObject() as RenderBox; + final RenderBox dynamicElementBox = dynamicElementKey.currentContext!.findRenderObject() as RenderBox; - if (_previousContainerHeight != containerBox.size.height || _previousDynamicElementHeight != dynamicElementBox.size.height) { - _previousContainerHeight = containerBox.size.height; - _previousDynamicElementHeight = dynamicElementBox.size.height; + final newContainerHeight = containerBox.size.height; + final newDynamicElementHeight = dynamicElementBox.size.height; - _containerHeight = containerBox.size.height + dynamicElementBox.size.height + parsedAddressTopPadding; + if (_previousContainerHeight != newContainerHeight || _previousDynamicElementHeight != newDynamicElementHeight) { + _previousContainerHeight = newContainerHeight; + _previousDynamicElementHeight = newDynamicElementHeight; + + _containerHeight = newContainerHeight + newDynamicElementHeight + additionalPadding; widget.heightNotifier.value = _containerHeight!; setState(() {}); } } } - - @override bool get wantKeepAlive => true; } + + +TextStyle genericTextStyle({ + double fontSize = 14, + FontWeight fontWeight = FontWeight.w600, + Color color = Colors.white, +}) { + return TextStyle( + fontSize: fontSize, + fontWeight: fontWeight, + color: color, + ); +}