mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-24 12:29:37 +00:00
desktop currency update on save only
This commit is contained in:
parent
07cf1f3f92
commit
cebbfcf82d
2 changed files with 55 additions and 23 deletions
|
@ -14,11 +14,10 @@ import 'package:stackwallet/widgets/desktop/primary_button.dart';
|
||||||
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
|
||||||
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
|
||||||
import 'package:stackwallet/widgets/rounded_container.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/stack_text_field.dart';
|
||||||
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
import 'package:stackwallet/widgets/textfield_icon_button.dart';
|
||||||
|
|
||||||
import '../../../widgets/rounded_white_container.dart';
|
|
||||||
|
|
||||||
class BaseCurrencySettingsView extends ConsumerStatefulWidget {
|
class BaseCurrencySettingsView extends ConsumerStatefulWidget {
|
||||||
const BaseCurrencySettingsView({Key? key}) : super(key: key);
|
const BaseCurrencySettingsView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@ -37,6 +36,11 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
final _searchFocusNode = FocusNode();
|
final _searchFocusNode = FocusNode();
|
||||||
|
|
||||||
void onTap(int index) {
|
void onTap(int index) {
|
||||||
|
if (Util.isDesktop) {
|
||||||
|
setState(() {
|
||||||
|
current = currenciesWithoutSelected[index];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
|
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
|
||||||
// ignore if already selected currency
|
// ignore if already selected currency
|
||||||
return;
|
return;
|
||||||
|
@ -46,6 +50,7 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
currenciesWithoutSelected.insert(0, current);
|
currenciesWithoutSelected.insert(0, current);
|
||||||
ref.read(prefsChangeNotifierProvider).currency = current;
|
ref.read(prefsChangeNotifierProvider).currency = current;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BorderRadius? _borderRadius(int index) {
|
BorderRadius? _borderRadius(int index) {
|
||||||
if (index == 0 && currenciesWithoutSelected.length == 1) {
|
if (index == 0 && currenciesWithoutSelected.length == 1) {
|
||||||
|
@ -82,6 +87,15 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
_searchController = TextEditingController();
|
_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();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +108,9 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isDesktop = Util.isDesktop;
|
||||||
|
|
||||||
|
if (!isDesktop) {
|
||||||
current = ref
|
current = ref
|
||||||
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
.watch(prefsChangeNotifierProvider.select((value) => value.currency));
|
||||||
|
|
||||||
|
@ -101,12 +118,14 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
.watch(baseCurrenciesProvider.select((value) => value.map))
|
.watch(baseCurrenciesProvider.select((value) => value.map))
|
||||||
.keys
|
.keys
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
if (current.isNotEmpty) {
|
if (current.isNotEmpty) {
|
||||||
currenciesWithoutSelected.remove(current);
|
currenciesWithoutSelected.remove(current);
|
||||||
currenciesWithoutSelected.insert(0, current);
|
currenciesWithoutSelected.insert(0, current);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
currenciesWithoutSelected = _filtered();
|
currenciesWithoutSelected = _filtered();
|
||||||
final isDesktop = Util.isDesktop;
|
|
||||||
|
|
||||||
return ConditionalParent(
|
return ConditionalParent(
|
||||||
condition: !isDesktop,
|
condition: !isDesktop,
|
||||||
|
@ -181,7 +200,20 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
child: PrimaryButton(
|
child: PrimaryButton(
|
||||||
label: "Save changes",
|
label: "Save changes",
|
||||||
desktopMed: true,
|
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();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -102,7 +102,7 @@ class _CurrencySettings extends ConsumerState<CurrencySettings> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.all(
|
padding: const EdgeInsets.all(
|
||||||
10,
|
10,
|
||||||
),
|
),
|
||||||
child: PrimaryButton(
|
child: PrimaryButton(
|
||||||
|
|
Loading…
Reference in a new issue