CWA-180 | added getCurrentDateFormat() to settings store, refactored date_section_raw, trade_details_page, transaction_details_page, dashboard_page

Oleksandr Sobol committed Mar 9, 2020 at 18:51 UTC 3d0d0521e4b162d6d8513eac2bf124d498622a4c
5 files changed +19 -15
lib/src/screens/dashboard/dashboard_page.dart
+3 -4
@@ -1,5 +1,4 @@
1 import 'package:provider/provider.dart';
2 -import 'package:intl/intl.dart';
2 import 'package:date_range_picker/date_range_picker.dart' as date_rage_picker;
3 import 'package:flutter/material.dart';
4 import 'package:flutter/cupertino.dart';
@@ -125,9 +124,9 @@ class DashboardPageBodyState extends State<DashboardPageBody> {
124 final actionListStore = Provider.of<ActionListStore>(context);
125 final syncStore = Provider.of<SyncStore>(context);
126 final settingsStore = Provider.of<SettingsStore>(context);
128 - final transactionDateFormat = settingsStore.currentLocale == 'en_US'
129 - ? DateFormat("MMMM d, yyyy, HH:mm", settingsStore.languageCode)
130 - : DateFormat("d MMMM yyyy, HH:mm", settingsStore.languageCode);
127 + final transactionDateFormat = settingsStore.getCurrentDateFormat(
128 + formatUSA: "MMMM d, yyyy, HH:mm",
129 + formatDefault: "d MMMM yyyy, HH:mm");
130
131 return Observer(
132 key: _listObserverKey,
lib/src/screens/dashboard/date_section_raw.dart
+3 -3
@@ -19,9 +19,9 @@ class DateSectionRaw extends StatelessWidget {
19 nowDate.year == date.year;
20 final settingsStore = Provider.of<SettingsStore>(context);
21 final currentLanguage = settingsStore.languageCode;
22 - final dateSectionDateFormat = settingsStore.currentLocale == 'en_US'
23 - ? DateFormat("MMM d", settingsStore.languageCode)
24 - : DateFormat("d MMM", settingsStore.languageCode);
22 + final dateSectionDateFormat = settingsStore.getCurrentDateFormat(
23 + formatUSA: "MMM d",
24 + formatDefault: "d MMM");
25 var title = "";
26
27 if (isToday) {
lib/src/screens/trade_details/trade_details_page.dart
+3 -4
@@ -9,7 +9,6 @@ import 'package:cake_wallet/src/stores/settings/settings_store.dart';
9 import 'package:cake_wallet/src/screens/base_page.dart';
10 import 'package:cake_wallet/src/screens/transaction_details/standart_list_item.dart';
11 import 'package:cake_wallet/src/screens/transaction_details/standart_list_row.dart';
12 -import 'package:intl/intl.dart';
12
13 class TradeDetailsPage extends BasePage {
14 @override
@@ -22,9 +21,9 @@ class TradeDetailsPage extends BasePage {
21 Widget body(BuildContext context) {
22 final exchangeStore = Provider.of<ExchangeTradeStore>(context);
23 final settingsStore = Provider.of<SettingsStore>(context);
25 - final createdAtFormat = settingsStore.currentLocale == 'en_US'
26 - ? DateFormat('yyyy.MM.dd, HH:mm')
27 - : DateFormat('dd.MM.yyyy, HH:mm');
24 + final createdAtFormat = settingsStore.getCurrentDateFormat(
25 + formatUSA: "yyyy.MM.dd, HH:mm",
26 + formatDefault: "dd.MM.yyyy, HH:mm");
27
28 return Container(
29 padding: EdgeInsets.only(top: 10.0, bottom: 10.0, left: 20, right: 15),
lib/src/screens/transaction_details/transaction_details_page.dart
+3 -4
@@ -1,4 +1,3 @@
1 -import 'package:intl/intl.dart';
1 import 'package:provider/provider.dart';
2 import 'package:flutter/material.dart';
3 import 'package:flutter/cupertino.dart';
@@ -46,9 +45,9 @@ class TransactionDetailsFormState extends State<TransactionDetailsForm> {
45
46 @override
47 void initState() {
49 - final _dateFormat = widget.settingsStore.currentLocale == 'en_US'
50 - ? DateFormat('yyyy.MM.dd, HH:mm')
51 - : DateFormat('dd.MM.yyyy, HH:mm');
48 + final _dateFormat = widget.settingsStore.getCurrentDateFormat(
49 + formatUSA: "yyyy.MM.dd, HH:mm",
50 + formatDefault: "dd.MM.yyyy, HH:mm");
51 final items = [
52 StandartListItem(
53 title: S.current.transaction_details_transaction_id,
lib/src/stores/settings/settings_store.dart
+7
@@ -15,6 +15,7 @@ import 'package:cake_wallet/src/domain/common/default_settings_migration.dart';
15 import 'package:package_info/package_info.dart';
16 import 'package:cake_wallet/src/domain/common/language.dart';
17 import 'package:devicelocale/devicelocale.dart';
18 +import 'package:intl/intl.dart';
19
20 part 'settings_store.g.dart';
21
@@ -287,4 +288,10 @@ abstract class SettingsStoreBase with Store {
288 await changeCurrentNodeToDefault(sharedPreferences: _sharedPreferences, nodes: _nodes);
289 await loadSettings();
290 }
291 +
292 + DateFormat getCurrentDateFormat({
293 + @required String formatUSA,
294 + @required String formatDefault}) => currentLocale == 'en_US'
295 + ? DateFormat(formatUSA, languageCode)
296 + : DateFormat(formatDefault, languageCode);
297 }