123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- import 'package:fis_i18n/i18n.dart';
- import 'package:flutter/material.dart';
- import 'package:flyinsonolite/controls/custom/customdatepicker.dart';
- import 'package:flyinsonolite/controls/custom/customiconbutton.dart';
- import 'package:flyinsonolite/controls/custom/customtextbutton.dart';
- import 'package:flyinsonolite/controls/text/fistextfield.dart';
- import 'package:flyinsonolite/infrastructure/scale.dart';
- import 'package:flyinsonolite/infrastructure/storage.dart';
- import 'package:intl/intl.dart';
- class DateTimeTextField extends StatelessWidget {
- final TextEditingController _dateController = TextEditingController();
- DateTime? selectedDate;
- String? placeHolder;
- TextStyle? textStyle;
- Color? borderColor;
- Color? enabledBorderColor;
- Color? fillColor;
- final ValueChanged<DateTime?>? dateChanged;
- bool selectableDayCheck = false;
- DateTimeTextField(this.placeHolder, this.selectedDate,
- {super.key,
- this.textStyle,
- this.borderColor,
- this.enabledBorderColor,
- this.fillColor,
- this.dateChanged,
- this.selectableDayCheck = false});
- @override
- Widget build(BuildContext context) {
- if (selectedDate != null) {
- _dateController.text = DateFormat('yyyy-MM-dd').format(selectedDate!);
- }
- return FISTextField(
- uniqueKey: null,
- contentPadding: EdgeInsets.fromLTRB(10.s, 0, 0, 0),
- textStyle: textStyle,
- readOnly: true,
- controller: _dateController,
- placeHolder: placeHolder,
- borderColor: borderColor,
- enabledBorderColor: enabledBorderColor,
- fillColor: fillColor,
- onTap: () async {
- await _showDatePickerAsync(context);
- },
- suffixIcon: CustomIconButton(
- constraints: const BoxConstraints(),
- padding: const EdgeInsets.all(0),
- onPressed: () async {
- await _showDatePickerAsync(context);
- },
- icon: Icon(
- Icons.date_range_rounded,
- size: 24.s,
- color: Storage.currentTheme.themeData.indicatorColor,
- ),
- ));
- }
- Future _showDatePickerAsync(BuildContext context) async {
- var pickedDate = await showCustomDatePicker(
- context: context,
- initialEntryMode: DatePickerEntryMode.calendarOnly,
- initialDate: selectedDate ?? DateTime.now(),
- firstDate: DateTime(2000),
- lastDate: DateTime(4000),
- locale: i18nBook.locale,
- currentDate: DateTime.now(),
- selectableDayPredicate: (day) {
- if (selectableDayCheck) {
- var earlyDatetime = DateTime.now();
- if (selectedDate != null) {
- if (selectedDate!.difference(DateTime.now()).inDays < 0) {
- earlyDatetime = selectedDate!;
- }
- }
- return day.difference(earlyDatetime).inDays >= 0;
- } else {
- return true;
- }
- },
- builder: (context, child) {
- return Theme(
- data: ThemeData(
- fontFamily: Storage.currentTheme.fontFamily,
- // 更改右侧时间字体的大小
- textTheme: TextTheme(
- titleSmall: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- titleMedium: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- titleLarge: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- bodySmall: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- bodyMedium: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- bodyLarge: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- labelSmall: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- labelMedium: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- labelLarge: TextStyle(
- fontSize: 18.s,
- color: const Color.fromRGBO(211, 211, 211, 1)),
- headlineSmall: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- headlineMedium: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- headlineLarge: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- displaySmall: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- displayMedium: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- displayLarge: TextStyle(
- fontSize: 20.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- ),
- inputDecorationTheme: InputDecorationTheme(
- labelStyle: TextStyle(
- fontSize: 22.s,
- color: const Color.fromRGBO(211, 211, 211, 1),
- ),
- ),
- dialogBackgroundColor:
- Storage.currentTheme.datePickerStyle.backgroundColor,
- colorScheme: ColorScheme.light(
- primary: Storage.currentTheme.datePickerStyle.leftSizeColor,
- onSurface: Storage.currentTheme.normalTextStyle.color!),
- textButtonTheme: TextButtonThemeData(
- style: CustomTextButton.styleFrom(
- foregroundColor:
- Storage.currentTheme.normalTextStyle.color,
- textStyle: Storage.currentTheme.normalTextStyle))),
- child: child!);
- },
- );
- if (pickedDate != null) {
- selectedDate = pickedDate;
- _dateController.text = DateFormat('yyyy-MM-dd').format(pickedDate);
- dateChanged!(pickedDate);
- }
- }
- }
|