68 lines
2.2 KiB
Dart
Executable File
68 lines
2.2 KiB
Dart
Executable File
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_cupertino_datetime_picker/flutter_cupertino_datetime_picker.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../translations/trans_lib.dart';
|
|
|
|
typedef DateValueCallback(DateTime dateTime, List<int> selectedIndex);
|
|
|
|
class ShowSelectDateTime {
|
|
|
|
void showDatePicker(BuildContext context, String maxT, String minT, String nowDate, String formatStr, DateValueCallback onConfirm,) {
|
|
// String MIN_DATETIME = '1900-01-01 00:00';
|
|
// String MAX_DATETIME = '2100-01-01 00:00';
|
|
// String INIT_DATETIME = getNowDate();
|
|
DateTime _dateTime = DateTime.parse(nowDate);
|
|
DateTimePickerLocale _locale = DateTimePickerLocale.zh_cn;
|
|
String _format = formatStr;
|
|
|
|
DatePicker.showDatePicker(
|
|
context,
|
|
onMonthChangeStartWithFirstDate: true,
|
|
pickerTheme: DateTimePickerTheme(
|
|
cancel: Text(TranslationLoader.lanKeys!.cancel!.tr, style: const TextStyle(color: Colors.black)),
|
|
showTitle: true,
|
|
confirm: Text('确定'.tr, style: const TextStyle(color: Colors.black)),
|
|
),
|
|
minDateTime: DateTime.parse(minT),
|
|
maxDateTime: DateTime.parse(maxT),
|
|
initialDateTime: _dateTime,
|
|
dateFormat: _format,
|
|
locale: _locale,
|
|
onClose: () {
|
|
|
|
},
|
|
onCancel: () {
|
|
|
|
},
|
|
onChange: (dateTime, List<int> index) {
|
|
|
|
},
|
|
onConfirm: onConfirm,
|
|
);
|
|
}
|
|
|
|
// String getNowDate(){
|
|
// // 获取当前时间对象
|
|
// DateTime today = DateTime.now();
|
|
// String dateSlug ="${today.year.toString()}-${today.month.toString().padLeft(2,'0')}-${today.day.toString().padLeft(2,'0')} ${today.hour.toString().padLeft(2,'0')}:${today.minute.toString().padLeft(2,'0')}";
|
|
//
|
|
// // //获取当前时间的年
|
|
// // int year = now.year;
|
|
// // //获取当前时间的月
|
|
// // int month = now.month;
|
|
// // //获取当前时间的日
|
|
// // int day = now.day;
|
|
// // //获取当前时间的时
|
|
// // int hour = now.hour;
|
|
// // //获取当前时间的分
|
|
// // int minute = now.minute;
|
|
// // //获取当前时间的秒
|
|
// // int millisecond = now.millisecond;
|
|
//
|
|
// // AppLog.log("组合 $year-$month-$day $hour:$minute:$millisecond");
|
|
// return dateSlug;
|
|
// }
|
|
}
|