defaultTextField static method

Widget defaultTextField({
  1. Key? key,
  2. required TextInputAction textInputAction,
  3. required TextInputType textInputType,
  4. required bool isLoading,
  5. required TextFieldController textFieldController,
  6. String? initialValue,
  7. IconData? iconData,
  8. bool hasInitialValue = false,
  9. bool readOnly = false,
  10. String? fontFamily,
})

Implementation

static Widget defaultTextField({
  Key? key,
  required TextInputAction textInputAction,
  required TextInputType textInputType,
  required bool isLoading,
  required TextFieldController textFieldController,
  String? initialValue,
  IconData? iconData,
  bool hasInitialValue = false,
  bool readOnly = false,
  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.h, right: 10.h),
          decoration: BoxDecoration(
            color: readOnly
                ? Colors.transparent
                : Get.theme.colorScheme.background,
            borderRadius: BorderRadius.all(Radius.circular(8.r)),
            border: Border.all(
              width: 1.w,
              color: !textFieldController.isValid
                  ? Get.theme.colorScheme.error
                  : readOnly
                      ? Colors.grey
                      : Get.theme.shadowColor,
            ),
          ),
          child: TextFormField(
            style: GoogleFonts.getFont(
              fontFamily ?? (Platform.isIOS ? 'Open Sans' : 'Roboto'),
            ),
            readOnly: readOnly,
            cursorColor: Get.theme.primaryColor,
            inputFormatters: textFieldController.inputFormatter ?? [],
            initialValue: textFieldController.text,
            enabled: !isLoading,
            obscureText: textFieldController.obscureText &&
                !textFieldController.visible,
            textInputAction: textInputAction,
            keyboardType: textInputType,
            onChanged: textFieldController.onChange,
            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: textFieldController.obscureText ||
                      textFieldController.visible
                  ? EdgeInsets.only(
                      top: 14.h,
                      bottom: 10.h,
                      left: 10.w,
                      right: 10.w,
                    )
                  : EdgeInsets.all(10.spMin),
              // labelText: textFieldController.title,
              hintText: textFieldController.title,
              icon: iconData == null
                  ? null
                  : Icon(
                      iconData,
                      color: Get.theme.primaryColor,
                    ),
              filled: true,
              fillColor: Colors.transparent,

              suffixIcon: textFieldController.obscureText ||
                      textFieldController.visible
                  ? IconButton(
                      padding: EdgeInsets.zero,
                      icon: Icon(
                        textFieldController.visible
                            ? Icons.visibility
                            : Icons.visibility_off,
                        // color: Colors.red,
                      ),
                      onPressed: textFieldController.toogleVisible,
                      splashRadius: 24.r,
                    )
                  : null,
            ),
          ),
        ),
      ),
      AnimatedSize(
        duration: const Duration(milliseconds: 300),
        child: !textFieldController.isValid
            ? Padding(
                padding: EdgeInsets.all(8.0.spMin),
                child: Texts.caption(
                  textFieldController.errorMessage,
                  color: Get.theme.colorScheme.error,
                  textOverflow: TextOverflow.visible,
                ),
              )
            : const SizedBox(),
      ),
    ],
  );
}