showDatePicker function
void
showDatePicker(
- BuildContext context, {
- bool useLight = true,
- Color textColor = Colors.black,
- DateTimePickerSelected? onDone,
- DateTime? initialDate,
- String? title,
show date picket dialog with cupertino style
Implementation
void showDatePicker(
BuildContext context, {
bool useLight = true,
Color textColor = Colors.black,
DateTimePickerSelected? onDone,
DateTime? initialDate,
String? title,
}) {
var selected = initialDate ?? DateTime.now();
var picker = () => CupertinoDatePicker(
initialDateTime: initialDate ?? DateTime.now(),
mode: CupertinoDatePickerMode.date,
onDateTimeChanged: (date) => selected = date,
);
showModalBottomSheet(
context: context,
builder: (ctx) {
return Container(
height: (MediaQuery.of(context).size.height / 3) + 50,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
Container(
color: Colors.white,
width: double.infinity,
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
Visibility(
visible: title != null,
child: Text(
title ?? "",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
Expanded(child: Container()),
Align(
alignment: Alignment.centerRight,
child: SizedBox(
height: 35,
width: 60,
child: CupertinoButton(
onPressed: () {
Navigator.pop(ctx);
if (onDone != null) onDone(selected);
},
padding: EdgeInsets.all(0),
child: Text(
"Done",
style: TextStyle(
color: CupertinoColors.activeBlue,
fontWeight: FontWeight.bold,
),
),
),
),
),
],
),
),
Expanded(
child: useLight
? Theme(data: ThemeData.light(), child: picker())
: picker(),
),
],
),
);
},
);
}