CAKE-97 | created date_picker for Android and iOS; applied date picker to blockchain_height_widget

OleksandrSobol committed Oct 1, 2020 at 20:29 UTC ae6291179e6b4f8ec45be2b9f8fe8809be8f64f9
4 files changed +61 -6
lib/src/widgets/blockchain_height_widget.dart
+2 -1
@@ -1,3 +1,4 @@
1 +import 'package:cake_wallet/utils/date_picker.dart';
2 import 'package:flutter/material.dart';
3 import 'package:intl/intl.dart';
4 import 'package:cake_wallet/generated/i18n.dart';
@@ -88,7 +89,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
89
90 Future _selectDate(BuildContext context) async {
91 final now = DateTime.now();
91 - final date = await showDatePicker(
92 + final date = await getDate(
93 context: context,
94 initialDate: now.subtract(Duration(days: 1)),
95 firstDate: DateTime(2014, DateTime.april),
lib/utils/date_picker.dart new
+54
@@ -0,0 +1,54 @@
1 +import 'dart:io';
2 +import 'package:flutter/cupertino.dart';
3 +import 'package:flutter/material.dart';
4 +
5 +Future<DateTime> getDate({
6 + @required BuildContext context,
7 + @required DateTime initialDate,
8 + @required DateTime firstDate,
9 + @required DateTime lastDate}) {
10 +
11 + if (Platform.isIOS) {
12 + return _buildCupertinoDataPicker(context, initialDate, firstDate, lastDate);
13 + }
14 +
15 + return _buildMaterialDataPicker(context, initialDate, firstDate, lastDate);
16 +}
17 +
18 +Future<DateTime> _buildMaterialDataPicker(
19 + BuildContext context,
20 + DateTime initialDate,
21 + DateTime firstDate,
22 + DateTime lastDate) async {
23 + return await showDatePicker(
24 + context: context,
25 + initialDate: initialDate,
26 + firstDate: firstDate,
27 + lastDate: lastDate,
28 + helpText: '');
29 +}
30 +
31 +Future<DateTime> _buildCupertinoDataPicker(
32 + BuildContext context,
33 + DateTime initialDate,
34 + DateTime firstDate,
35 + DateTime lastDate) async {
36 + DateTime date;
37 + await showModalBottomSheet<void>(
38 + context: context,
39 + builder: (_) {
40 + return Container(
41 + height: MediaQuery.of(context).size.height / 3,
42 + child: CupertinoDatePicker(
43 + mode: CupertinoDatePickerMode.date,
44 + onDateTimeChanged: (picked) => date = picked,
45 + initialDateTime: initialDate,
46 + minimumDate: firstDate,
47 + maximumDate: lastDate,
48 + backgroundColor: Colors.white,
49 + ),
50 + );
51 + }
52 + );
53 + return date;
54 +}
\ No newline at end of file
lib/utils/show_pop_up.dart
+2 -2
@@ -14,8 +14,8 @@ Future<T> showPopUp<T>({
14 context: context,
15 builder: builder,
16 barrierDismissible: barrierDismissible,
17 - //barrierColor: barrierColor,
18 - //useSafeArea: useSafeArea,
17 + barrierColor: barrierColor,
18 + useSafeArea: useSafeArea,
19 useRootNavigator: useRootNavigator,
20 routeSettings: routeSettings,
21 child: child);
pubspec.lock
+3 -3
@@ -589,7 +589,7 @@ packages:
589 name: mobx_codegen
590 url: "https://pub.dartlang.org"
591 source: hosted
592 - version: "1.1.0+1"
592 + version: "1.1.0+2"
593 node_interop:
594 dependency: transitive
595 description:
@@ -708,7 +708,7 @@ packages:
708 name: plugin_platform_interface
709 url: "https://pub.dartlang.org"
710 source: hosted
711 - version: "1.0.2"
711 + version: "1.0.3"
712 pointycastle:
713 dependency: transitive
714 description:
@@ -1030,5 +1030,5 @@ packages:
1030 source: hosted
1031 version: "2.2.1"
1032 sdks:
1033 - dart: ">=2.7.0 <3.0.0"
1033 + dart: ">=2.7.2 <3.0.0"
1034 flutter: ">=1.12.13+hotfix.5 <2.0.0"