Flutter - How to view Prefix on TextFormField even not pressed

Viewed 1840

Im new to flutter, i want to view the prefix text in textformfield even not on pressed. My code:

TextFormField(
 decoration: InputDecoration(
   prefix: Text("Subject: ",
     style: TextStyle(color: Colors.black),),
   hintText: "Unique Subject",
   border: OutlineInputBorder(),
),

Sorry for the img link, im still new to stackoverflow still havent reached 10 reputations.

This is my result:

Result

This is what i want, even textformfield havent been pressed

Output

Thanks

2 Answers

There are few workarounds for this. To know more use this as reference: https://github.com/flutter/flutter/issues/19488

prefixIcon: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10),
                      child: Text('Subject:',style: TextStyle(color: Colors.black),),
                    )
                  ],),
                  hintText: "Unique Subject",
                  border: OutlineInputBorder(),

You just need to use the prefixIcon or suffixIcon attribute of the InputDecoration instead of the prefixText/suffixText.

Related