import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; class DynamicTextFieldWidget extends StatelessWidget { final String labelText; final String hintText; final TextEditingController? controller; final VoidCallback? onTap; final IconData? suffixIconData; final bool isEnable; final TextInputAction? inputAction; final bool isReadOnly; final bool isPopup; final int? lines; final bool isInputTypeNum; final bool isInputTypeNumSigned; final bool isObscureText; final bool isBackgroundEnable; final void Function(String)? onChange; final int? maxLength; final List? inputFormatters; final Color? backgroundColor; final Color? borderColor; final double? borderWidth; final Color? labelColor; final Color? textColor; final Color? suffixIconColor; final BorderRadius? borderRadius; final List? boxShadow; final BoxConstraints? constraints; final EdgeInsetsGeometry? padding; DynamicTextFieldWidget(this.labelText, this.hintText, {this.controller, this.isObscureText = false, this.onTap, this.suffixIconData, this.isEnable = true, this.isReadOnly = false, this.isPopup = false, this.lines = 1, this.inputAction, this.onChange, this.isInputTypeNum = false, this.isInputTypeNumSigned = true, this.isBackgroundEnable = false, this.maxLength, this.inputFormatters, this.backgroundColor, this.borderColor, this.borderWidth, this.labelColor, this.textColor, this.suffixIconColor, this.borderRadius, this.boxShadow, this.constraints, this.padding}); @override Widget build(BuildContext context) { Color effectiveBorderColor = borderColor ?? MyColors.lightGreyEFColor; double effectiveBorderWidth = borderWidth ?? 1.0; Color effectiveLabelColor = labelColor ?? const Color(0xff2B353E); Color effectiveTextColor = textColor ?? const Color(0xff2B353E); Color effectiveSuffixColor = suffixIconColor ?? MyColors.darkIconColor; return Container( constraints: constraints, padding: padding ?? const EdgeInsets.only(left: 16, right: 16, bottom: 15, top: 15), alignment: Alignment.center, decoration: BoxDecoration( borderRadius: borderRadius ?? BorderRadius.circular(15), color: backgroundColor ?? (isReadOnly ? MyColors.lightGreyEFColor : Colors.white), border: Border.all( color: effectiveBorderColor, width: effectiveBorderWidth, ), boxShadow: boxShadow, ), child: InkWell( onTap: onTap, child: Row( children: [ Expanded( child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ if (labelText.isNotEmpty) Text( labelText, style: TextStyle( fontSize: 11, fontWeight: FontWeight.w600, color: effectiveLabelColor, letterSpacing: -0.44, ), ), TextField( controller: controller, enabled: isEnable, scrollPadding: EdgeInsets.zero, readOnly: isReadOnly, keyboardType: (isInputTypeNum) ? (isInputTypeNumSigned ? const TextInputType.numberWithOptions(signed: true, decimal: true) : TextInputType.numberWithOptions(signed: true, decimal: true)) : TextInputType.text, textInputAction: TextInputAction.done, maxLines: lines, maxLength: maxLength, inputFormatters: inputFormatters, obscuringCharacter: "*", obscureText: isObscureText, onChanged: onChange, style: TextStyle( fontSize: 14, height: 21 / 14, fontWeight: FontWeight.w400, color: effectiveTextColor, letterSpacing: -0.44, ), decoration: InputDecoration( counterText: "", isDense: true, hintText: hintText, fillColor: backgroundColor ?? (isReadOnly ? MyColors.borderColor : null), hintStyle: const TextStyle( fontSize: 14, height: 21 / 14, fontWeight: FontWeight.w400, color: Color(0xff575757), letterSpacing: -0.56, ), contentPadding: EdgeInsets.zero, border: InputBorder.none, focusedBorder: InputBorder.none, enabledBorder: InputBorder.none, ), ), ], ), ), if (isPopup) Icon(Icons.keyboard_arrow_down_outlined, color: effectiveSuffixColor) else if (onTap != null) Icon(suffixIconData ?? Icons.keyboard_arrow_down_outlined, color: effectiveSuffixColor) else if (suffixIconData != null) Icon(suffixIconData, color: effectiveSuffixColor), ], ), ), ); } }