Implementation
String getPresentationWidgetsTextInputWidgetTemplate(String projectName) {
return '''
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:${projectName}/core/constants/app_strings.dart';
import 'package:${projectName}/core/theme/app_colors.dart';
import 'package:${projectName}/core/utils/responsive_size.dart';
class CommonTextFormField extends StatelessWidget {
final bool? isPassword;
final bool? showPassword;
final bool? isSuffixShow;
final double? borderRadius;
final double? height;
final double? fontSize;
final EdgeInsets? padding;
final int? maxLines;
final int? minLines;
final bool? isExpand;
final bool? isReadOnly;
final FocusNode? focusNode;
final String? hintText;
final String? labelText;
final String? errorText;
final String? initialValue;
final String? helperText;
final String? fontFamily;
final Color? borderColor;
final Color? hintColor;
final Widget? prefixWidget;
final Widget? suffixWidget;
final VoidCallback? suffixTap;
final Function(String)? onChanged;
final FormFieldValidator<String>? validator;
final int? maxLength;
final TextEditingController? controller;
final Color? fillColor;
final TextInputType? textInputType;
final VoidCallback? fieldTap;
final bool? enter;
final TextInputAction? textInputAction;
const CommonTextFormField({
super.key,
this.isPassword,
this.showPassword,
this.isSuffixShow,
this.borderRadius,
this.height,
this.fontSize,
this.padding,
this.maxLines,
this.isReadOnly,
this.focusNode,
this.hintText,
this.labelText,
this.errorText,
this.initialValue,
this.helperText,
this.borderColor,
this.fontFamily,
this.hintColor,
this.prefixWidget,
this.suffixWidget,
this.suffixTap,
this.onChanged,
this.validator,
this.maxLength,
this.minLines,
this.isExpand,
this.controller,
this.fillColor,
this.textInputType,
this.fieldTap,
this.enter = false,
this.textInputAction,
});
@override
Widget build(BuildContext context) {
return SizedBox(
height: height,
child: TextFormField(
onTap: isReadOnly == true ? fieldTap : null,
controller: controller,
focusNode: focusNode,
autofocus: false,
cursorColor: Colors.black,
initialValue: initialValue,
obscureText: isPassword ?? false,
onChanged: onChanged,
validator: validator,
readOnly: isReadOnly ?? false,
textAlign: TextAlign.start,
textAlignVertical: isExpand == true
? TextAlignVertical.top
: TextAlignVertical.center,
expands: isExpand ?? false,
minLines: isExpand == true ? null : minLines ?? 1,
maxLines: isExpand == true ? null : maxLines ?? 1,
maxLength: maxLength ?? 100,
maxLengthEnforcement: MaxLengthEnforcement.enforced,
autovalidateMode: AutovalidateMode.onUserInteraction,
textInputAction: enter == true ? TextInputAction.newline : null,
style: TextStyle(
fontSize: fontSize ?? 14.sp,
fontWeight: FontWeight.w400,
color: AppColors.black,
),
keyboardType: textInputType ?? TextInputType.text,
decoration: InputDecoration(
contentPadding:
padding ??
EdgeInsets.only(left: 15, top: 14, bottom: 14, right: 12),
fillColor: fillColor ?? Colors.white,
filled: true,
counter: const Offstage(),
hintText: hintText,
labelText: labelText,
errorText: errorText,
helperText: helperText,
errorStyle: TextStyle(
color: Colors.red,
fontSize: 11.sp,
fontWeight: FontWeight.w600,
fontFamily: fontFamily ?? AppStrings.appFontDMSans,
),
hintStyle: TextStyle(
color: hintColor ?? AppColors.grey,
fontSize: 14.sp,
fontWeight: FontWeight.w400,
fontFamily: fontFamily ?? AppStrings.appFontDMSans,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(
borderRadius ?? 12.0,
), // Customize when disabled
borderSide: BorderSide(
color: borderColor ?? AppColors.themeBorder,
), // Example color
),
// Or UnderlineInputBorder()
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
borderRadius ?? 12.0,
), // Customize when enabled
borderSide: BorderSide(
color: borderColor ?? AppColors.themeBorder,
), // Example color
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
borderRadius ?? 12.0,
), // Customize when focused
borderSide: BorderSide(
color: borderColor ?? AppColors.themeBorder,
), // Example color
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(
borderRadius ?? 12.0,
), // Customize when error
borderSide: BorderSide(
color: Colors.red,
width: 1,
), // Example color
),
focusedErrorBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.red, width: 1),
borderRadius: BorderRadius.circular(borderRadius ?? 12.sp),
),
errorMaxLines: 5,
prefixIcon: prefixWidget,
suffixIcon: suffixWidget != null
? GestureDetector(onTap: suffixTap, child: suffixWidget)
: null,
),
),
);
}
}
''';
}