From b33e7b8aecd4b793dc98eadccf017282c815bc8f Mon Sep 17 00:00:00 2001 From: Justin Enerio Date: Fri, 11 Oct 2024 04:41:54 +0800 Subject: [PATCH] feat: ramp amount screen updates (#1590) --- .../ramp/screens/ramp_amount_screen.dart | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/packages/espressocash_app/lib/features/ramp/screens/ramp_amount_screen.dart b/packages/espressocash_app/lib/features/ramp/screens/ramp_amount_screen.dart index 33c8f0359..9a4553fc6 100644 --- a/packages/espressocash_app/lib/features/ramp/screens/ramp_amount_screen.dart +++ b/packages/espressocash_app/lib/features/ramp/screens/ramp_amount_screen.dart @@ -90,6 +90,7 @@ class RampAmountScreen extends StatefulWidget { class _RampAmountScreenState extends State { final _controller = TextEditingController(); + final _minimumAmountNoticeKey = GlobalKey<_MinimumAmountNoticeState>(); @override void dispose() { @@ -109,6 +110,16 @@ class _RampAmountScreenState extends State { ); } + void _onSubmit() { + final amount = _amount; + + if (amount.decimal >= widget.minAmount) { + widget.onSubmitted(amount); + } else { + _minimumAmountNoticeKey.currentState?.showNotice(); + } + } + @override Widget build(BuildContext context) => CpTheme.dark( child: Scaffold( @@ -163,7 +174,7 @@ class _RampAmountScreenState extends State { valueListenable: _controller, builder: (context, value, child) => _MinimumAmountNotice( - controller: _controller, + key: _minimumAmountNoticeKey, currency: widget.currency, amount: _amount, minAmount: widget.minAmount, @@ -191,17 +202,11 @@ class _RampAmountScreenState extends State { ), child: ValueListenableBuilder( valueListenable: _controller, - builder: (context, value, child) { - final amount = _amount; - - return CpButton( - width: double.infinity, - text: context.l10n.next, - onPressed: amount.decimal >= widget.minAmount - ? () => widget.onSubmitted(amount) - : null, - ); - }, + builder: (context, value, child) => CpButton( + width: double.infinity, + text: context.l10n.next, + onPressed: _onSubmit, + ), ), ), ], @@ -217,14 +222,13 @@ class _RampAmountScreenState extends State { class _MinimumAmountNotice extends StatefulWidget { const _MinimumAmountNotice({ - required this.controller, - required this.amount, + super.key, required this.minAmount, required this.type, required this.currency, + required this.amount, }); - final TextEditingController controller; final Amount amount; final Decimal minAmount; final RampType type; @@ -249,14 +253,17 @@ class _MinimumAmountNoticeState extends State<_MinimumAmountNotice> } void _updateVisibility() { - final newVisible = widget.amount.decimal != Decimal.zero && - widget.amount.decimal < widget.minAmount; - if (_visible != newVisible) { - _visible = newVisible; + if (widget.amount.decimal >= widget.minAmount) { + _visible = false; } - if (_visible) { + } + + // ignore: prefer-widget-private-members, used for controlling state + void showNotice() { + setState(() { + _visible = true; _shakeKey.currentState?.shake(); - } + }); } @override