2020-10-01 17:29:06 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<DateTime?> getDate({
|
|
|
|
required BuildContext context,
|
|
|
|
required DateTime initialDate,
|
|
|
|
required DateTime firstDate,
|
|
|
|
required DateTime lastDate}) {
|
2020-10-01 17:29:06 +00:00
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
return _buildCupertinoDataPicker(context, initialDate, firstDate, lastDate);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _buildMaterialDataPicker(context, initialDate, firstDate, lastDate);
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<DateTime?> _buildMaterialDataPicker(
|
2020-10-01 17:29:06 +00:00
|
|
|
BuildContext context,
|
|
|
|
DateTime initialDate,
|
|
|
|
DateTime firstDate,
|
|
|
|
DateTime lastDate) async {
|
|
|
|
return await showDatePicker(
|
|
|
|
context: context,
|
|
|
|
initialDate: initialDate,
|
|
|
|
firstDate: firstDate,
|
|
|
|
lastDate: lastDate,
|
|
|
|
helpText: '');
|
|
|
|
}
|
|
|
|
|
2022-10-12 17:09:57 +00:00
|
|
|
Future<DateTime?> _buildCupertinoDataPicker(
|
2020-10-01 17:29:06 +00:00
|
|
|
BuildContext context,
|
|
|
|
DateTime initialDate,
|
|
|
|
DateTime firstDate,
|
|
|
|
DateTime lastDate) async {
|
2022-10-12 17:09:57 +00:00
|
|
|
DateTime? date;
|
2020-10-01 17:29:06 +00:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return date;
|
|
|
|
}
|