Skip to content

Commit e6a1211

Browse files
committed
Changed date picker on iOS to CupertinoDatePicker
1 parent 95d8ce1 commit e6a1211

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Fixed failure of web OTP on iOS devices
44
* Automatically closes soft keyboard when text-field entries are submitted
5+
* Changed date picker on iOS to CupertinoDatePicker
56

67
## 0.9.2
78

lib/src/widgets/birthday_widget.dart

+51-17
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import 'dart:async';
1+
import 'dart:io';
22

33
import 'package:flutter/material.dart';
4+
import 'package:flutter/cupertino.dart';
45
import 'package:flutter_paystack/src/widgets/base_widget.dart';
56
import 'package:flutter_paystack/src/widgets/buttons.dart';
67
import 'package:flutter_paystack/src/widgets/custom_dialog.dart';
78
import 'package:intl/intl.dart';
89

10+
const double _kPickerSheetHeight = 216.0;
11+
912
class BirthdayWidget extends StatefulWidget {
1013
final String message;
1114

12-
// TODO: Use iOS date picker
13-
1415
BirthdayWidget({@required this.message});
1516

1617
@override
@@ -86,22 +87,55 @@ class _BirthdayWidgetState extends BaseState<BirthdayWidget> {
8687
));
8788
}
8889

89-
Future<DateTime> _showDatePicker() {
90+
void _selectBirthday() async {
91+
updateDate(date) {
92+
setState(() => _pickedDate = date);
93+
}
94+
9095
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);
101136

102-
void _selectBirthday() async {
103-
DateTime result = await _showDatePicker();
104-
setState(() => _pickedDate = result);
137+
updateDate(result);
138+
}
105139
}
106140

107141
Widget dateItem(String text) {

0 commit comments

Comments
 (0)