mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 20:09:23 +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,14 +36,20 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
final _searchFocusNode = FocusNode();
|
final _searchFocusNode = FocusNode();
|
||||||
|
|
||||||
void onTap(int index) {
|
void onTap(int index) {
|
||||||
if (currenciesWithoutSelected[index] == current || current.isEmpty) {
|
if (Util.isDesktop) {
|
||||||
// ignore if already selected currency
|
setState(() {
|
||||||
return;
|
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) {
|
BorderRadius? _borderRadius(int index) {
|
||||||
|
@ -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,20 +108,25 @@ class _CurrencyViewState extends ConsumerState<BaseCurrencySettingsView> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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;
|
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(
|
return ConditionalParent(
|
||||||
condition: !isDesktop,
|
condition: !isDesktop,
|
||||||
builder: (child) {
|
builder: (child) {
|
||||||
|
@ -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