mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
connect toggle to preferences and use value in parent buy form
This commit is contained in:
parent
6a2c0c4d8a
commit
ac2775dc42
3 changed files with 33 additions and 36 deletions
|
@ -42,6 +42,8 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
final FocusNode _fiatFocusNode = FocusNode();
|
||||
final FocusNode _cryptoFocusNode = FocusNode();
|
||||
|
||||
bool buyWithFiat = true;
|
||||
|
||||
void fiatFieldOnChanged(String value) async {
|
||||
if (_fiatFocusNode.hasFocus) {
|
||||
final newFromAmount = Decimal.tryParse(value);
|
||||
|
@ -470,6 +472,9 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
Widget build(BuildContext context) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
||||
buyWithFiat = ref.watch(
|
||||
prefsChangeNotifierProvider.select((value) => value.buyWithFiat));
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
|
@ -557,7 +562,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
|
|||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
"Enter amount",
|
||||
buyWithFiat ? "Enter amount" : "Enter crypto amount",
|
||||
style: STextStyles.itemSubtitle(context).copyWith(
|
||||
color: Theme.of(context).extension<StackColors>()!.textDark3,
|
||||
),
|
||||
|
|
|
@ -1,57 +1,29 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/utilities/util.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
|
||||
class FiatCryptoToggle extends ConsumerWidget {
|
||||
const FiatCryptoToggle({
|
||||
Key? key,
|
||||
// this.onChanged,
|
||||
}) : super(key: key);
|
||||
|
||||
// final void Function(ExchangeRateType)? onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
final isDesktop = Util.isDesktop;
|
||||
|
||||
// final estimated = ref.watch(prefsChangeNotifierProvider
|
||||
// .select((value) => value.exchangeRateType)) ==
|
||||
// ExchangeRateType.estimated;
|
||||
final buyWithFiat = ref.watch(
|
||||
prefsChangeNotifierProvider.select((value) => value.buyWithFiat));
|
||||
|
||||
// return Toggle(
|
||||
// onValueChanged: (value) {
|
||||
// // if (!estimated) {
|
||||
// // ref.read(prefsChangeNotifierProvider).exchangeRateType =
|
||||
// // ExchangeRateType.estimated;
|
||||
// // onChanged?.call(ExchangeRateType.estimated);
|
||||
// // } else {
|
||||
// // onChanged?.call(ExchangeRateType.fixed);
|
||||
// // }
|
||||
// },
|
||||
// isOn: true,
|
||||
// onColor: Theme.of(context).extension<StackColors>()!.textFieldDefaultBG,
|
||||
// offColor: isDesktop
|
||||
// ? Theme.of(context).extension<StackColors>()!.buttonBackSecondary
|
||||
// : Theme.of(context).extension<StackColors>()!.popupBG,
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(
|
||||
// Constants.size.circularBorderRadius,
|
||||
// ),
|
||||
// ),
|
||||
// onIcon: Assets.svg.lockOpen,
|
||||
// onText: "Estimate rate",
|
||||
// offIcon: Assets.svg.lock,
|
||||
// offText: "Fixed rate",
|
||||
// );
|
||||
return BlueTextButton(
|
||||
text: "Use crypto amount",
|
||||
text: buyWithFiat ? "Use crypto amount" : "Use fiat amount",
|
||||
textSize: 14,
|
||||
onTap: () {
|
||||
// Navigator.of(context).pushNamed(
|
||||
// ForgotPasswordDesktopView.routeName,
|
||||
// );
|
||||
final buyWithFiat = ref.read(prefsChangeNotifierProvider).buyWithFiat;
|
||||
ref.read(prefsChangeNotifierProvider).buyWithFiat = !buyWithFiat;
|
||||
// Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class Prefs extends ChangeNotifier {
|
|||
_startupWalletId = await _getStartupWalletId();
|
||||
_externalCalls = await _getHasExternalCalls();
|
||||
_familiarity = await _getHasFamiliarity();
|
||||
_buyWithFiat = await _getBuyWithFiat();
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
@ -350,6 +351,25 @@ class Prefs extends ChangeNotifier {
|
|||
0;
|
||||
}
|
||||
|
||||
// buy with fiat (default) or crypto
|
||||
bool _buyWithFiat = true;
|
||||
bool get buyWithFiat => _buyWithFiat;
|
||||
|
||||
set buyWithFiat(bool buyWithFiat) {
|
||||
if (this.buyWithFiat != buyWithFiat) {
|
||||
DB.instance.put<dynamic>(
|
||||
boxName: DB.boxNamePrefs, key: "buyWithFiat", value: buyWithFiat);
|
||||
_buyWithFiat = buyWithFiat;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _getBuyWithFiat() async {
|
||||
return await DB.instance.get<dynamic>(
|
||||
boxName: DB.boxNamePrefs, key: "buyWithFiat") as bool? ??
|
||||
true;
|
||||
}
|
||||
|
||||
// show testnet coins
|
||||
|
||||
bool _showTestNetCoins = false;
|
||||
|
|
Loading…
Reference in a new issue