desktop currency update on save only

This commit is contained in:
julian 2022-11-15 17:45:16 -06:00
parent 07cf1f3f92
commit cebbfcf82d
2 changed files with 55 additions and 23 deletions

View file

@ -14,11 +14,10 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
import 'package:stackwallet/widgets/rounded_container.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart';
import '../../../widgets/rounded_white_container.dart';
class BaseCurrencySettingsView extends ConsumerStatefulWidget {
const BaseCurrencySettingsView({Key? key}) : super(key: key);
@ -37,6 +36,11 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
final _searchFocusNode = FocusNode();
void onTap(int index) {
if (Util.isDesktop) {
setState(() {
current = currenciesWithoutSelected[index];
});
} else {
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
// ignore if already selected currency
return;
@ -46,6 +50,7 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
currenciesWithoutSelected.insert(0, current);
ref.read(prefsChangeNotifierProvider).currency = current;
}
}
BorderRadius? _borderRadius(int index) {
if (index == 0 && currenciesWithoutSelected.length == 1) {
@ -82,6 +87,15 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
@override
void initState() {
_searchController = TextEditingController();
if (Util.isDesktop) {
currenciesWithoutSelected =
ref.read(baseCurrenciesProvider).map.keys.toList();
current = ref.read(prefsChangeNotifierProvider).currency;
if (current.isNotEmpty) {
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
}
}
super.initState();
}
@ -94,6 +108,9 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
@override
Widget build(BuildContext context) {
final isDesktop = Util.isDesktop;
if (!isDesktop) {
current = ref
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
@ -101,12 +118,14 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
.watch(baseCurrenciesProvider.select((value) => value.map))
.keys
.toList();
if (current.isNotEmpty) {
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
}
}
currenciesWithoutSelected = _filtered();
final isDesktop = Util.isDesktop;
return ConditionalParent(
condition: !isDesktop,
@ -181,7 +200,20 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
child: PrimaryButton(
label: "Save changes",
desktopMed: true,
onPressed: Navigator.of(context).pop,
onPressed: () {
ref.read(prefsChangeNotifierProvider).currency =
current;
if (ref
.read(prefsChangeNotifierProvider)
.externalCalls) {
ref
.read(priceAnd24hChangeNotifierProvider)
.updatePrice();
}
Navigator.of(context).pop();
},
),
),
],

View file

@ -102,7 +102,7 @@ class _CurrencySettings extends ConsumerState<CurrencySettings> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.all(
padding: const EdgeInsets.all(
10,
),
child: PrimaryButton(