I am trying to achieve the TextFormField
just like the image attached.
This is my code currently:
@override
Widget build(BuildContext context) {
return TextFormField(
focusNode: _textFieldFocus,
controller: widget.controller,
decoration: InputDecoration(
filled: true,
fillColor: _color,
prefixIcon: _buildPrefixIcon(),
labelText: widget.hintText,
hintStyle: context.textStyle.subHeadline.copyWith(color: widget.hintColor ?? context.colors.textSecondaryOnLightBackground),
contentPadding: const EdgeInsets.symmetric(vertical: 0, horizontal: 8),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: context.colors.fieldsColor),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: context.colors.fieldsColor),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: context.colors.fieldsColor),
),
),
style: context.textStyle.subHeadline.copyWith(color: widget.textColor ?? context.colors.textPrimaryOnLightBackground),
textInputAction: widget.textInputAction,
keyboardType: widget.keyboardType,
obscureText: widget.obscureText ?? false,
onChanged: widget.onChanged,
);
}
Is there a way to create a floating hint inside the outline border?
2
Answers
I just managed to find a workaround. I just wrap the
TextFormField
withContainer
, set theTextFormField
border asUnderlineInputBorder
, and make the border side transparent or the background color of the screen so that the underline border will disappear.Let me know if there's any solution that can also worked.
Remove the border from the
TextField
itself, and wrap it with aContainer
that you will use to theme your text field.Output:
Code: