mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 09:47:35 +00:00
Merge pull request #117 from cake-tech/CAKE-97-date-picker-for-ios
Cake 97 date picker for ios
This commit is contained in:
commit
a8695cc560
2 changed files with 56 additions and 1 deletions
|
@ -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<BlockchainHeightWidget> {
|
|||
|
||||
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),
|
||||
|
|
54
lib/utils/date_picker.dart
Normal file
54
lib/utils/date_picker.dart
Normal file
|
@ -0,0 +1,54 @@
|
|||
import 'dart:io';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Future<DateTime> 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<DateTime> _buildMaterialDataPicker(
|
||||
BuildContext context,
|
||||
DateTime initialDate,
|
||||
DateTime firstDate,
|
||||
DateTime lastDate) async {
|
||||
return await showDatePicker(
|
||||
context: context,
|
||||
initialDate: initialDate,
|
||||
firstDate: firstDate,
|
||||
lastDate: lastDate,
|
||||
helpText: '');
|
||||
}
|
||||
|
||||
Future<DateTime> _buildCupertinoDataPicker(
|
||||
BuildContext context,
|
||||
DateTime initialDate,
|
||||
DateTime firstDate,
|
||||
DateTime lastDate) async {
|
||||
DateTime date;
|
||||
await showModalBottomSheet<void>(
|
||||
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;
|
||||
}
|
Loading…
Reference in a new issue