|
1 | | -import 'dart:async'; |
| 1 | +import 'dart:io'; |
2 | 2 |
|
3 | 3 | import 'package:flutter/material.dart'; |
| 4 | +import 'package:flutter/cupertino.dart'; |
4 | 5 | import 'package:flutter_paystack/src/widgets/base_widget.dart'; |
5 | 6 | import 'package:flutter_paystack/src/widgets/buttons.dart'; |
6 | 7 | import 'package:flutter_paystack/src/widgets/custom_dialog.dart'; |
7 | 8 | import 'package:intl/intl.dart'; |
8 | 9 |
|
| 10 | +const double _kPickerSheetHeight = 216.0; |
| 11 | + |
9 | 12 | class BirthdayWidget extends StatefulWidget { |
10 | 13 | final String message; |
11 | 14 |
|
12 | | - // TODO: Use iOS date picker |
13 | | - |
14 | 15 | BirthdayWidget({@required this.message}); |
15 | 16 |
|
16 | 17 | @override |
@@ -86,22 +87,55 @@ class _BirthdayWidgetState extends BaseState<BirthdayWidget> { |
86 | 87 | )); |
87 | 88 | } |
88 | 89 |
|
89 | | - Future<DateTime> _showDatePicker() { |
| 90 | + void _selectBirthday() async { |
| 91 | + updateDate(date) { |
| 92 | + setState(() => _pickedDate = date); |
| 93 | + } |
| 94 | + |
90 | 95 | var now = new DateTime.now(); |
91 | | - return showDatePicker( |
92 | | - context: context, |
93 | | - selectableDayPredicate: (DateTime val) => |
94 | | - val.year > now.year && val.month > now.month && val.day > now.day |
95 | | - ? false |
96 | | - : true, |
97 | | - initialDate: now, |
98 | | - firstDate: new DateTime(1900), |
99 | | - lastDate: now); |
100 | | - } |
| 96 | + var minimumYear = 1900; |
| 97 | + if (Platform.isIOS) { |
| 98 | + showCupertinoModalPopup<void>( |
| 99 | + context: context, |
| 100 | + builder: (BuildContext context) => Container( |
| 101 | + height: _kPickerSheetHeight, |
| 102 | + padding: const EdgeInsets.only(top: 6.0), |
| 103 | + color: CupertinoColors.white, |
| 104 | + child: DefaultTextStyle( |
| 105 | + style: const TextStyle( |
| 106 | + color: CupertinoColors.black, |
| 107 | + fontSize: 22.0, |
| 108 | + ), |
| 109 | + child: GestureDetector( |
| 110 | + // Blocks taps from propagating to the modal sheet and popping. |
| 111 | + onTap: () {}, |
| 112 | + child: SafeArea( |
| 113 | + top: false, |
| 114 | + child: new CupertinoDatePicker( |
| 115 | + mode: CupertinoDatePickerMode.date, |
| 116 | + initialDateTime: now, |
| 117 | + maximumDate: now, |
| 118 | + minimumYear: minimumYear, |
| 119 | + maximumYear: now.year, |
| 120 | + onDateTimeChanged: updateDate, |
| 121 | + ), |
| 122 | + ), |
| 123 | + ), |
| 124 | + ), |
| 125 | + )); |
| 126 | + } else { |
| 127 | + DateTime result = await showDatePicker( |
| 128 | + context: context, |
| 129 | + selectableDayPredicate: (DateTime val) => |
| 130 | + val.year > now.year && val.month > now.month && val.day > now.day |
| 131 | + ? false |
| 132 | + : true, |
| 133 | + initialDate: now, |
| 134 | + firstDate: new DateTime(minimumYear), |
| 135 | + lastDate: now); |
101 | 136 |
|
102 | | - void _selectBirthday() async { |
103 | | - DateTime result = await _showDatePicker(); |
104 | | - setState(() => _pickedDate = result); |
| 137 | + updateDate(result); |
| 138 | + } |
105 | 139 | } |
106 | 140 |
|
107 | 141 | Widget dateItem(String text) { |
|
0 commit comments