Search code examples
flutterdartflutter-layout

Flutter - How to view Prefix on TextFormField even not pressed


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


Solution

  • 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(),