mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
wrap in popScope to prevent error on back button press
This commit is contained in:
@@ -55,78 +55,81 @@ class _NewBuySellAmountPageState extends State<NewBuySellAmountPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(18)),
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.surface,
|
||||
Theme.of(context).colorScheme.surfaceDim,
|
||||
],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
return PopScope(
|
||||
onPopInvokedWithResult: (didPop, result) => Navigator.of(context, rootNavigator: true).pop(),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(18)),
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Theme.of(context).colorScheme.surface,
|
||||
Theme.of(context).colorScheme.surfaceDim,
|
||||
],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Observer(
|
||||
builder: (_) => ModalTopBar(
|
||||
title: _pageTitle,
|
||||
bottomText: !_customAmountMode || widget.buySellViewModel.maxFiatAmount == null
|
||||
? null
|
||||
: "${S.of(context).up_to} ~${widget.buySellViewModel.maxFiatAmount} ${widget.buySellViewModel.fiatCurrency.title}",
|
||||
leadingIcon: Icon(Icons.close),
|
||||
onLeadingPressed: Navigator.of(context, rootNavigator: true).pop,
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Observer(
|
||||
builder: (_) => ModalTopBar(
|
||||
title: _pageTitle,
|
||||
bottomText: !_customAmountMode || widget.buySellViewModel.maxFiatAmount == null
|
||||
? null
|
||||
: "${S.of(context).up_to} ~${widget.buySellViewModel.maxFiatAmount} ${widget.buySellViewModel.fiatCurrency.title}",
|
||||
leadingIcon: Icon(Icons.close),
|
||||
onLeadingPressed: Navigator.of(context, rootNavigator: true).pop,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Observer(
|
||||
builder: (_) => AnimatedSwitcher(
|
||||
duration: Duration(milliseconds: 300),
|
||||
child: _customAmountMode
|
||||
? BuySellCustomAmountInput(
|
||||
fiatCurrency: widget.buySellViewModel.fiatCurrency,
|
||||
cryptoCurrency: widget.buySellViewModel.cryptoCurrency,
|
||||
cryptoAmount: widget.buySellViewModel.cryptoAmount,
|
||||
isLoading: _isLoadingPaymentMethods,
|
||||
hasCurrencySelector: widget.buySellViewModel.hasMultipleCurrencies,
|
||||
onCurrencySelectorPressed: () => selectCryptoCurrency(context),
|
||||
controller: customInputController,
|
||||
focusNode: customInputFocusNode,
|
||||
onContinuePressed: () {
|
||||
navigateToProviders(context);
|
||||
},
|
||||
onChanged: (amount) =>
|
||||
widget.buySellViewModel.changeFiatAmount(amount: amount),
|
||||
)
|
||||
: BuySellDefaultAmountSelector(
|
||||
key: ValueKey(0),
|
||||
defaultAmounts: widget.buySellViewModel.defaultAmounts,
|
||||
fiatCurrency: widget.buySellViewModel.fiatCurrency,
|
||||
currentAmount: widget.buySellViewModel.fiatAmount,
|
||||
hasCurrencySelector: widget.buySellViewModel.hasMultipleCurrencies,
|
||||
onCurrencySelectorPressed: () => selectCryptoCurrency(context),
|
||||
cryptoCurrency: widget.buySellViewModel.cryptoCurrency,
|
||||
isLoading: _isLoadingPaymentMethods,
|
||||
mode: widget.buySellViewModel.mode,
|
||||
onSelected: (amount) async {
|
||||
if (amount == null) {
|
||||
// this resets the rate and prevents showing 0 usd = 0.something btc
|
||||
await widget.buySellViewModel.changeFiatAmount(amount: "");
|
||||
setState(() {
|
||||
_customAmountMode = true;
|
||||
});
|
||||
customInputFocusNode.requestFocus();
|
||||
} else {
|
||||
await widget.buySellViewModel.changeFiatAmount(amount: amount);
|
||||
Expanded(
|
||||
child: Observer(
|
||||
builder: (_) => AnimatedSwitcher(
|
||||
duration: Duration(milliseconds: 300),
|
||||
child: _customAmountMode
|
||||
? BuySellCustomAmountInput(
|
||||
fiatCurrency: widget.buySellViewModel.fiatCurrency,
|
||||
cryptoCurrency: widget.buySellViewModel.cryptoCurrency,
|
||||
cryptoAmount: widget.buySellViewModel.cryptoAmount,
|
||||
isLoading: _isLoadingPaymentMethods,
|
||||
hasCurrencySelector: widget.buySellViewModel.hasMultipleCurrencies,
|
||||
onCurrencySelectorPressed: () => selectCryptoCurrency(context),
|
||||
controller: customInputController,
|
||||
focusNode: customInputFocusNode,
|
||||
onContinuePressed: () {
|
||||
navigateToProviders(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
))
|
||||
],
|
||||
},
|
||||
onChanged: (amount) =>
|
||||
widget.buySellViewModel.changeFiatAmount(amount: amount),
|
||||
)
|
||||
: BuySellDefaultAmountSelector(
|
||||
key: ValueKey(0),
|
||||
defaultAmounts: widget.buySellViewModel.defaultAmounts,
|
||||
fiatCurrency: widget.buySellViewModel.fiatCurrency,
|
||||
currentAmount: widget.buySellViewModel.fiatAmount,
|
||||
hasCurrencySelector: widget.buySellViewModel.hasMultipleCurrencies,
|
||||
onCurrencySelectorPressed: () => selectCryptoCurrency(context),
|
||||
cryptoCurrency: widget.buySellViewModel.cryptoCurrency,
|
||||
isLoading: _isLoadingPaymentMethods,
|
||||
mode: widget.buySellViewModel.mode,
|
||||
onSelected: (amount) async {
|
||||
if (amount == null) {
|
||||
// this resets the rate and prevents showing 0 usd = 0.something btc
|
||||
await widget.buySellViewModel.changeFiatAmount(amount: "");
|
||||
setState(() {
|
||||
_customAmountMode = true;
|
||||
});
|
||||
customInputFocusNode.requestFocus();
|
||||
} else {
|
||||
await widget.buySellViewModel.changeFiatAmount(amount: amount);
|
||||
navigateToProviders(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user