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,14 +36,20 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
final _searchFocusNode = FocusNode();
void onTap(int index) {
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
// ignore if already selected currency
return;
if (Util.isDesktop) {
setState(() {
current = currenciesWithoutSelected[index];
});
} else {
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
// ignore if already selected currency
return;
}
current = currenciesWithoutSelected[index];
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
ref.read(prefsChangeNotifierProvider).currency = current;
}
current = currenciesWithoutSelected[index];
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
ref.read(prefsChangeNotifierProvider).currency = current;
}
BorderRadius? _borderRadius(int index) {
@ -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,20 +108,25 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
@override
Widget build(BuildContext context) {
current = ref
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
currenciesWithoutSelected = ref
.watch(baseCurrenciesProvider.select((value) => value.map))
.keys
.toList();
if (current.isNotEmpty) {
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
}
currenciesWithoutSelected = _filtered();
final isDesktop = Util.isDesktop;
if (!isDesktop) {
current = ref
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
currenciesWithoutSelected = ref
.watch(baseCurrenciesProvider.select((value) => value.map))
.keys
.toList();
if (current.isNotEmpty) {
currenciesWithoutSelected.remove(current);
currenciesWithoutSelected.insert(0, current);
}
}
currenciesWithoutSelected = _filtered();
return ConditionalParent(
condition: !isDesktop,
builder: (child) {
@ -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(