buildTextField method
Widget
buildTextField(
- HMTextFieldType type,
- TextEditingController controller,
- HMTextFieldSize fieldSize,
- HMTextVariant fieldVariant,
- HMRadius fieldRadius,
- Color fieldIconColor,
- Color background,
- HMTextFieldTheme? textFieldTheme, {
- required Color disableTextColor,
Implementation
Widget buildTextField(
HMTextFieldType type,
TextEditingController controller,
HMTextFieldSize fieldSize,
HMTextVariant fieldVariant,
HMRadius fieldRadius,
Color fieldIconColor,
Color background,
HMTextFieldTheme? textFieldTheme,
{required Color disableTextColor}) {
final textSize = _getTextSize(fieldSize);
final showPassword = useState(false);
switch (type) {
case HMTextFieldType.text:
return SizedBox(
child: Row(
children: <Widget>[
if (prefixIcon != null)
Padding(
padding: const EdgeInsets.only(right: 10),
child: _buildPrefixIcon(_getTextSize(fieldSize)),
),
// const SizedBox(width: 10),
Expanded(
child: TextField(
keyboardType: TextInputType.text,
textInputAction: textInputAction,
controller: controller,
focusNode: focusNode,
style: TextStyle(
color: disabled ? disableTextColor : null,
fontSize: textSize,
),
textCapitalization: TextCapitalization.sentences,
autocorrect: !(keyboardType == TextInputType.emailAddress),
maxLength: maxLength,
textAlignVertical: TextAlignVertical.center,
inputFormatters: inputFormatters,
decoration: InputDecoration.collapsed(
hintText: hintText,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: textSize,
fontWeight: FontWeight.normal),
),
onTap: onTap,
onChanged: onChange,
onSubmitted: onSubmitted,
onEditingComplete: onEditingComplete,
),
),
// const SizedBox(width: 10),
if (suffixIcon != null)
Padding(
padding: const EdgeInsets.only(left: 10),
child: _buildSuffixIcon(_getTextSize(fieldSize)),
),
],
),
);
case HMTextFieldType.password:
return SizedBox(
child: Row(
children: <Widget>[
if (prefixIcon != null)
Padding(
padding: const EdgeInsets.only(right: 10),
child: _buildPrefixIcon(_getTextSize(fieldSize)),
),
// const SizedBox(width: 10),
Expanded(
child: TextField(
keyboardType: TextInputType.visiblePassword,
controller: controller,
style: TextStyle(
color: disabled ? disableTextColor : null,
fontSize: textSize,
),
obscureText: !showPassword.value,
textInputAction: textInputAction,
autocorrect: false,
focusNode: focusNode,
maxLength: maxLength,
decoration: InputDecoration.collapsed(
hintText: hintText,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: textSize,
fontWeight: FontWeight.normal),
),
onTap: onTap,
onChanged: onChange,
onSubmitted: onSubmitted,
onEditingComplete: onEditingComplete,
),
),
// const SizedBox(width: 10),
GestureDetector(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Container(
constraints: BoxConstraints(minHeight: textSize * 2),
child: IconTheme(
data: IconThemeData(
size: textSize * 1.5,
color: Colors.grey,
),
child: showPassword.value
? hidePasswordIcon ??
textFieldTheme?.hidePasswordIcon ??
const Icon(Icons.visibility_off)
: showPasswordIcon ??
textFieldTheme?.showPasswordIcon ??
const Icon(Icons.visibility),
),
),
),
onTap: () {
showPassword.value = !showPassword.value;
},
),
],
),
);
case HMTextFieldType.number:
return SizedBox(
child: Row(
children: <Widget>[
if (prefixIcon != null)
Padding(
padding: const EdgeInsets.only(right: 10),
child: _buildPrefixIcon(_getTextSize(fieldSize)),
),
Expanded(
child: TextField(
controller: controller,
style: TextStyle(
color: disabled ? disableTextColor : null,
fontSize: textSize,
),
textInputAction: textInputAction,
keyboardType: TextInputType.number,
autocorrect: false,
focusNode: focusNode,
maxLength: maxLength,
decoration: InputDecoration.collapsed(
hintText: hintText,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: textSize,
fontWeight: FontWeight.normal),
),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'[0-9]+[,.]{0,1}[0-9]*')),
TextInputFormatter.withFunction(
(oldValue, newValue) => newValue.copyWith(
text: newValue.text.replaceAll(',', '.'),
),
),
...?inputFormatters,
],
onTap: onTap,
onChanged: onChange,
onSubmitted: onSubmitted,
onEditingComplete: onEditingComplete,
),
),
],
),
);
case HMTextFieldType.multiline:
return SizedBox(
child: Row(
children: <Widget>[
if (prefixIcon != null)
Padding(
padding: const EdgeInsets.only(right: 10),
child: _buildPrefixIcon(_getTextSize(fieldSize)),
),
// const SizedBox(width: 10),
Expanded(
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: TextField(
controller: controller,
style: TextStyle(
color: disabled ? disableTextColor : null,
fontSize: textSize,
),
keyboardType: TextInputType.multiline,
textCapitalization: TextCapitalization.sentences,
// textInputAction: textInputAction,
focusNode: focusNode,
minLines: minLines,
maxLines: maxLines,
maxLength: maxLength,
inputFormatters: inputFormatters,
decoration: InputDecoration.collapsed(
hintText: hintText,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: textSize,
fontWeight: FontWeight.normal),
),
onTap: onTap,
onChanged: onChange,
onSubmitted: onSubmitted,
onEditingComplete: onEditingComplete,
),
),
),
if (suffixIcon != null)
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: _buildSuffixIcon(_getTextSize(fieldSize)),
),
],
),
);
}
}