You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aku_new_community/lib/widget/picker/bee_date_picker.dart

84 lines
2.0 KiB

import 'package:flutter/cupertino.dart';
3 years ago
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
3 years ago
import 'package:aku_new_community/widget/picker/bee_custom_picker.dart';
3 years ago
import 'package:aku_new_community/widget/picker/bee_month_pick_body.dart';
class BeeDatePicker {
static Future<DateTime?> pick(DateTime initDate, {
CupertinoDatePickerMode mode = CupertinoDatePickerMode.date,
DateTime? min,
DateTime? max,
}) async {
return await Get.bottomSheet(_BeeDatePicker(
date: initDate,
mode: mode,
min: min ?? DateTime.now().subtract(Duration(days: 1)),
max: max,
));
}
4 years ago
static Future<DateTime?> timePicker(DateTime initDate) async {
return await Get.bottomSheet(_BeeDatePicker(
date: initDate,
min: initDate,
max: initDate.add(Duration(days: 7)),
mode: CupertinoDatePickerMode.dateAndTime,
));
}
static Future<DateTime?> monthPicker(DateTime initDate) async {
return await Get.bottomSheet(
BeeMonthPickBody(initTime: initDate)
);
}
}
class _BeeDatePicker extends StatefulWidget {
final DateTime date;
final bool use24H;
4 years ago
final DateTime? max;
final DateTime? min;
final CupertinoDatePickerMode? mode;
3 years ago
_BeeDatePicker({
4 years ago
Key? key,
required this.date,
this.use24H = false,
this.max,
this.min,
this.mode,
}) : super(key: key);
@override
__BeeDatePickerState createState() => __BeeDatePickerState();
}
class __BeeDatePickerState extends State<_BeeDatePicker> {
DateTime _date = DateTime.now();
3 years ago
@override
void initState() {
super.initState();
4 years ago
_date = widget.date;
}
@override
Widget build(BuildContext context) {
return BeeCustomPicker(
onPressed: () => Get.back(result: _date),
body: CupertinoDatePicker(
use24hFormat: widget.use24H,
maximumDate: widget.max,
minimumDate: widget.min,
initialDateTime: _date,
onDateTimeChanged: (date) => _date = date,
mode: widget.mode ?? CupertinoDatePickerMode.date,
).expand(),
);
}
}