Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a Hint Text above the Text Field

Email_On_Top_Hint

I am trying to accomplish showing a HintText on top of the textField. I have tried using a Labeltext but I can't get it to do this. This is my code :

@override
Widget build(BuildContext context) {
return TextFormField(
  keyboardType: textInputType,
  controller: controller,
  obscureText: obscureText,
  autocorrect: false,
  autofocus: autofocus,
  textAlign: TextAlign.center,
  cursorColor: BPColor.black,
  style: TextStyle(
    color: textColor,
    fontSize: 16,
  ),
  decoration: InputDecoration(
    hintText: hintText,
    fillColor: color,
    filled: true,
    hintStyle: TextStyle(color: textColor),
    contentPadding: EdgeInsets.all(10),
    enabledBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.white),
      borderRadius: BorderRadius.circular(0),
    ),
    focusedBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.white),
      borderRadius: BorderRadius.circular(0),
    ),
    errorBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.white),
      borderRadius: BorderRadius.circular(0),
    ),
    disabledBorder: OutlineInputBorder(
      borderSide: BorderSide(color: Colors.white),
      borderRadius: BorderRadius.circular(0),
    ),
  ),
);
}

This is the output of my TextField code:

TextField

I need to show the Email Hint outside of the TextField Box. Is there a way to accomplish this ? Or do I have to create a label outside of the TextField ?

When I add LabelText:

lbel_text

It shows like this :

enter image description here

Does not show right .

like image 626
Moses Avatar asked Oct 20 '25 13:10

Moses


2 Answers

Fot putting lable outside the textfield you can use Column and put Text and TextField as a widget over there. Use below code for reference.

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text('blahf blahh'),
        TextFormField(
          keyboardType: textInputType,
          controller: controller,
          obscureText: obscureText,
          autocorrect: false,
          autofocus: autofocus,
          textAlign: TextAlign.center,
          cursorColor: BPColor.black,
          style: TextStyle(
            color: textColor,
            fontSize: 16,
          ),
          decoration: InputDecoration(
            hintText: hintText,
            fillColor: color,
            filled: true,
            hintStyle: TextStyle(color: textColor),
            contentPadding: EdgeInsets.all(10),
            enabledBorder: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.white),
              borderRadius: BorderRadius.circular(0),
            ),
            focusedBorder: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.white),
              borderRadius: BorderRadius.circular(0),
            ),
            errorBorder: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.white),
              borderRadius: BorderRadius.circular(0),
            ),
            disabledBorder: OutlineInputBorder(
              borderSide: BorderSide(color: Colors.white),
              borderRadius: BorderRadius.circular(0),
            ),
          ),
        )
      ],
    );
  }
like image 172
Avinash Avatar answered Oct 23 '25 03:10

Avinash


What's wrong with this:

TextFormField(
  decoration: InputDecoration(labelText: 'Your hint'),
)
like image 34
iDecode Avatar answered Oct 23 '25 02:10

iDecode