From ae6291179e6b4f8ec45be2b9f8fe8809be8f64f9 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Thu, 1 Oct 2020 20:29:06 +0300 Subject: [PATCH] CAKE-97 | created date_picker for Android and iOS; applied date picker to blockchain_height_widget --- lib/src/widgets/blockchain_height_widget.dart | 3 +- lib/utils/date_picker.dart | 54 +++++++++++++++++++ lib/utils/show_pop_up.dart | 4 +- pubspec.lock | 6 +-- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 lib/utils/date_picker.dart diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart index 87d64b22..de242d45 100644 --- a/lib/src/widgets/blockchain_height_widget.dart +++ b/lib/src/widgets/blockchain_height_widget.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/date_picker.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -88,7 +89,7 @@ class BlockchainHeightState extends State { Future _selectDate(BuildContext context) async { final now = DateTime.now(); - final date = await showDatePicker( + final date = await getDate( context: context, initialDate: now.subtract(Duration(days: 1)), firstDate: DateTime(2014, DateTime.april), diff --git a/lib/utils/date_picker.dart b/lib/utils/date_picker.dart new file mode 100644 index 00000000..78e49666 --- /dev/null +++ b/lib/utils/date_picker.dart @@ -0,0 +1,54 @@ +import 'dart:io'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +Future getDate({ + @required BuildContext context, + @required DateTime initialDate, + @required DateTime firstDate, + @required DateTime lastDate}) { + + if (Platform.isIOS) { + return _buildCupertinoDataPicker(context, initialDate, firstDate, lastDate); + } + + return _buildMaterialDataPicker(context, initialDate, firstDate, lastDate); +} + +Future _buildMaterialDataPicker( + BuildContext context, + DateTime initialDate, + DateTime firstDate, + DateTime lastDate) async { + return await showDatePicker( + context: context, + initialDate: initialDate, + firstDate: firstDate, + lastDate: lastDate, + helpText: ''); +} + +Future _buildCupertinoDataPicker( + BuildContext context, + DateTime initialDate, + DateTime firstDate, + DateTime lastDate) async { + DateTime date; + await showModalBottomSheet( + context: context, + builder: (_) { + return Container( + height: MediaQuery.of(context).size.height / 3, + child: CupertinoDatePicker( + mode: CupertinoDatePickerMode.date, + onDateTimeChanged: (picked) => date = picked, + initialDateTime: initialDate, + minimumDate: firstDate, + maximumDate: lastDate, + backgroundColor: Colors.white, + ), + ); + } + ); + return date; +} \ No newline at end of file diff --git a/lib/utils/show_pop_up.dart b/lib/utils/show_pop_up.dart index 280bcff3..a97fb376 100644 --- a/lib/utils/show_pop_up.dart +++ b/lib/utils/show_pop_up.dart @@ -14,8 +14,8 @@ Future showPopUp({ context: context, builder: builder, barrierDismissible: barrierDismissible, - //barrierColor: barrierColor, - //useSafeArea: useSafeArea, + barrierColor: barrierColor, + useSafeArea: useSafeArea, useRootNavigator: useRootNavigator, routeSettings: routeSettings, child: child); diff --git a/pubspec.lock b/pubspec.lock index 9b56163b..4bfc5f79 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -589,7 +589,7 @@ packages: name: mobx_codegen url: "https://pub.dartlang.org" source: hosted - version: "1.1.0+1" + version: "1.1.0+2" node_interop: dependency: transitive description: @@ -708,7 +708,7 @@ packages: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "1.0.3" pointycastle: dependency: transitive description: @@ -1030,5 +1030,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.7.2 <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0"