dateTextField static method
Widget
dateTextField({
- Key? key,
- required TextInputAction textInputAction,
- required TextInputType textInputType,
- required bool isLoading,
- required DatePickerController datePickerController,
- IconData? iconData,
- String? fontFamily,
Implementation
static Widget dateTextField({
Key? key,
required TextInputAction textInputAction,
required TextInputType textInputType,
required bool isLoading,
required DatePickerController datePickerController,
IconData? iconData,
String? fontFamily,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AnimatedSize(
duration: const Duration(milliseconds: 300),
child: Container(
margin: EdgeInsets.only(
top: 10.h,
),
padding: EdgeInsets.only(left: 10.w, right: 10.w),
decoration: BoxDecoration(
color: Get.theme.colorScheme.background,
borderRadius: BorderRadius.all(Radius.circular(10.r)),
border: Border.all(
width: 1.w,
color: !datePickerController.isValid
? Colors.red
: Get.theme.shadowColor,
),
),
child: TextFormField(
// initialValue: datePickerController.text,
onTap: iconData == null
? () async {
final DateTime? picked = await showDatePicker(
context: Get.context!,
initialDate: DateTime.now(),
firstDate: DateTime(1945, 8),
lastDate: DateTime(2101),
builder: (context, child) {
return Theme(
data: Get.theme.brightness == Brightness.light
? Get.theme.copyWith(
// Light Theme
colorScheme: ColorScheme.light(
primary: Get
.theme.primaryColor, // <-- SEE HERE
// onPrimary: Get.theme., // <-- SEE HERE
onSurface: Get.theme.textTheme.bodyLarge!
.color!, // <-- SEE HERE
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Get.theme
.primaryColor, // button text color
),
),
)
: Get.theme.copyWith(
// Dark Theme
colorScheme: ColorScheme.light(
primary: Get
.theme.primaryColor, // <-- SEE HERE
// onPrimary: Colors.amber, // <-- SEE HERE
onSurface: Get.theme.textTheme.bodyLarge!
.color!, // <-- SEE HERE
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Get.theme
.primaryColor, // button text color
),
),
),
child: child!,
);
},
);
if (picked != null) {
datePickerController.changeDate(picked);
}
}
: null,
controller: datePickerController.textEditingController,
readOnly: true,
textInputAction: textInputAction,
keyboardType: textInputType,
style: GoogleFonts.getFont(
fontFamily ?? (Platform.isIOS ? 'Open Sans' : 'Roboto'),
),
decoration: InputDecoration(
hintStyle: GoogleFonts.getFont(
fontFamily ?? (Platform.isIOS ? 'Open Sans' : 'Roboto'),
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(vertical: 10.h, horizontal: 10.w),
hintText: datePickerController.title,
icon: iconData == null
? null
: Icon(
iconData,
),
filled: true,
fillColor: Colors.transparent,
suffixIcon: IconButton(
icon: iconData == null ? const SizedBox() : Icon(iconData),
onPressed: iconData == null
? () {}
: () async {
final DateTime? picked = await showDatePicker(
context: Get.context!,
initialDate: DateTime.now(),
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
builder: (context, child) {
return Theme(
data: Get.theme.brightness == Brightness.light
? Get.theme.copyWith(
// Light Theme
colorScheme: ColorScheme.light(
primary: Get.theme
.primaryColor, // <-- SEE HERE
// onPrimary: Get.theme., // <-- SEE HERE
// onSurface: Colors.blueAccent, // <-- SEE HERE
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Get.theme
.primaryColor, // button text color
),
),
)
: Get.theme.copyWith(
// Dark Theme
colorScheme: ColorScheme.light(
primary: Get.theme
.primaryColor, // <-- SEE HERE
// onPrimary: Colors.amber, // <-- SEE HERE
onSurface:
Colors.white, // <-- SEE HERE
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: Get.theme
.primaryColor, // button text color
),
),
),
child: child!,
);
},
);
if (picked != null) {
datePickerController.changeDate(picked);
}
},
splashRadius: 24.r,
),
),
),
),
),
AnimatedSize(
duration: const Duration(milliseconds: 300),
child: !datePickerController.isValid
? Padding(
padding: EdgeInsets.all(8.0.spMin),
child: Texts.overline(
datePickerController.errorMessage,
color: Get.theme.colorScheme.error,
textOverflow: TextOverflow.visible,
),
)
: const SizedBox(),
),
],
);
}