From cce358b94f55c22e0807b4d3641a13ebd299106c Mon Sep 17 00:00:00 2001 From: Serhii Date: Thu, 31 Oct 2024 22:02:47 +0200 Subject: [PATCH] hide picker after the country is set --- lib/entities/country.dart | 4 ++ .../cake_pay/cards/cake_pay_cards_page.dart | 55 ++++++++++--------- .../cake_pay_cards_list_view_model.dart | 11 ++++ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/lib/entities/country.dart b/lib/entities/country.dart index 63eee9a18..170e66a6a 100644 --- a/lib/entities/country.dart +++ b/lib/entities/country.dart @@ -376,6 +376,10 @@ class Country extends EnumerableItem with Serializable { return _all.values.firstWhereOrNull((element) => element.raw == countryCode.toLowerCase()); } + static Country? fromFullName(String fullName) { + return _all.values.firstWhereOrNull((element) => element.fullName == fullName); + } + @override bool operator ==(Object other) => other is Country && other.raw == raw; diff --git a/lib/src/screens/cake_pay/cards/cake_pay_cards_page.dart b/lib/src/screens/cake_pay/cards/cake_pay_cards_page.dart index eb9893a40..00e4999c5 100644 --- a/lib/src/screens/cake_pay/cards/cake_pay_cards_page.dart +++ b/lib/src/screens/cake_pay/cards/cake_pay_cards_page.dart @@ -119,36 +119,39 @@ class CakePayCardsPage extends BasePage { _cardsListViewModel.getVendors(); } }, - child: Container( - padding: EdgeInsets.symmetric(horizontal: 6), - decoration: BoxDecoration( - color: Theme.of(context).extension()!.syncedBackgroundColor, - border: Border.all(color: Colors.transparent), - borderRadius: BorderRadius.circular(10), - ), + child: Padding( + padding: const EdgeInsets.only(left: 5), child: Container( - margin: EdgeInsets.symmetric(vertical: 2), - child: Row( - children: [ - Image.asset( - _cardsListViewModel.selectedCountry.iconPath, - width: 24, - height: 24, - errorBuilder: (context, error, stackTrace) => Container( + padding: EdgeInsets.symmetric(horizontal: 6), + decoration: BoxDecoration( + color: Theme.of(context).extension()!.syncedBackgroundColor, + border: Border.all(color: Colors.transparent), + borderRadius: BorderRadius.circular(10), + ), + child: Container( + margin: EdgeInsets.symmetric(vertical: 2), + child: Row( + children: [ + Image.asset( + _cardsListViewModel.selectedCountry.iconPath, width: 24, height: 24, + errorBuilder: (context, error, stackTrace) => Container( + width: 24, + height: 24, + ), ), - ), - SizedBox(width: 6), - Text( - _cardsListViewModel.selectedCountry.countryCode, - style: TextStyle( - color: Theme.of(context).extension()!.textColor, - fontSize: 16, - fontWeight: FontWeight.w700, + SizedBox(width: 6), + Text( + _cardsListViewModel.selectedCountry.countryCode, + style: TextStyle( + color: Theme.of(context).extension()!.textColor, + fontSize: 16, + fontWeight: FontWeight.w700, + ), ), - ), - ], + ], + ), ), ), ), @@ -169,7 +172,7 @@ class CakePayCardsPage extends BasePage { )), SizedBox(width: 5), filterButton, - SizedBox(width: 5), + if (_cardsListViewModel.showCountryPicker) _countryPicker ])), SizedBox(height: 8), diff --git a/lib/view_model/cake_pay/cake_pay_cards_list_view_model.dart b/lib/view_model/cake_pay/cake_pay_cards_list_view_model.dart index a675a8600..d7b9f3fb0 100644 --- a/lib/view_model/cake_pay/cake_pay_cards_list_view_model.dart +++ b/lib/view_model/cake_pay/cake_pay_cards_list_view_model.dart @@ -5,6 +5,7 @@ import 'package:cake_wallet/entities/country.dart'; import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cake_wallet/view_model/dashboard/dropdown_filter_item.dart'; import 'package:cake_wallet/view_model/dashboard/filter_item.dart'; import 'package:mobx/mobx.dart'; @@ -70,6 +71,14 @@ abstract class CakePayCardsListViewModelBase with Store { caption: S.current.custom_value, onChanged: toggleCustomValueCards), ], + S.current.countries: [ + DropdownFilterItem( + items: availableCountries.map((e) => e.title).toList(), + caption: '', + selectedItem: selectedCountry.title, + onItemSelected: (String value) => setSelectedCountry(Country.fromFullName(value)!), + ), + ] }; String searchString; @@ -121,6 +130,8 @@ abstract class CakePayCardsListViewModelBase with Store { Country get selectedCountry => settingsStore.selectedCakePayCountry ?? _getInitialCountry(settingsStore.fiatCurrency); + bool get showCountryPicker => settingsStore.selectedCakePayCountry == null; + bool get hasFiltersChanged => settingsStore.selectedCakePayCountry != _initialSelectedCountry || displayPrepaidCards != _initialDisplayPrepaidCards ||