dateAndTimeTextField static method

Widget dateAndTimeTextField({
  1. Key? key,
  2. required TextInputAction textInputAction,
  3. required TextInputType textInputType,
  4. required bool isLoading,
  5. required DateAndTimePickerController dateAndTimePickerController,
  6. String? initialValue,
  7. IconData? iconData,
  8. String? fontFamily,
})

Implementation

static Widget dateAndTimeTextField({
  Key? key,
  required TextInputAction textInputAction,
  required TextInputType textInputType,
  required bool isLoading,
  required DateAndTimePickerController dateAndTimePickerController,
  String? initialValue,
  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.scaffoldBackgroundColor,
            borderRadius: BorderRadius.all(Radius.circular(10.r)),
            border: Border.all(
              width: 1.w,
              color: !dateAndTimePickerController.isValid
                  ? Colors.red
                  : Get.theme.shadowColor,
            ),
          ),
          child: TextFormField(
            style: GoogleFonts.getFont(
              fontFamily ?? (Platform.isIOS ? 'Open Sans' : 'Roboto'),
            ),
            controller: dateAndTimePickerController.textEditingController,
            readOnly: true,
            textInputAction: textInputAction,
            keyboardType: textInputType,
            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: dateAndTimePickerController.title,
              icon: iconData == null
                  ? null
                  : Icon(
                      iconData,
                    ),
              filled: true,
              fillColor: Get.theme.colorScheme.background,
              suffixIcon: IconButton(
                icon: const Icon(
                  Icons.date_range,
                ),
                onPressed: () async {
                  final DateTime? datePick = 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!,
                      );
                    },
                  );

                  final TimeOfDay? timePick = await showTimePicker(
                    context: Get.context!,
                    initialTime: TimeOfDay.now(),
                    builder: (context, child) => MediaQuery(
                      data: MediaQuery.of(context)
                          .copyWith(alwaysUse24HourFormat: true),
                      child: child ?? Container(),
                    ),
                  );

                  if (datePick != null && timePick != null) {
                    dateAndTimePickerController.changeDate(
                      datePick,
                      timePick,
                    );
                  }
                },
                splashRadius: 24.r,
              ),
            ),
          ),
        ),
      ),
      AnimatedSize(
        duration: const Duration(milliseconds: 300),
        child: !dateAndTimePickerController.isValid
            ? Padding(
                padding: EdgeInsets.all(8.0.spMin),
                child: Texts.overline(
                  dateAndTimePickerController.errorMessage,
                  color: Get.theme.colorScheme.error,
                  textOverflow: TextOverflow.visible,
                ),
              )
            : const SizedBox(),
      ),
    ],
  );
}