Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Outline input border

I was trying to build a border for my text field like:

return TextField(
  ...
 border: OutlineInputBorder(
  borderSide: BorderSide(
   color: Colors.red, 
    width: 5.0),
    )
  )
)

But it always return a black border with 1.0 as width. The only way that I found to change the color was to create a ThemeData where I specify the hint color, but I could not find a way to change my width.

like image 337
Little Monkey Avatar asked Jan 11 '19 09:01

Little Monkey


People also ask

How do you outline border to TextField in Flutter?

To add a border to a TextField/TextFormField in Flutter, you can specify the decoration property and then use the InputDecoration and OutlineInputBorder widget. The OutlineInputBorder widget has the borderSide widget which you can use to pass in the BorderSide widget with width and color parameter to create the border.

How do I remove the outline border in TextField Flutter?

To remove TextField underline/border in Flutter, you can simply set the border property to InputBorder. none. This will remove the underline for all states such as Focused, Enabled, Error, Disabled.


2 Answers

What your looking for is - enabledBorder property of InputDecoration.

If you want to Change Border on focus use - focusedBorder

    TextField(
        decoration: new InputDecoration(
            focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.greenAccent, width: 5.0),
            ),
            enabledBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.red, width: 5.0),
            ),
            hintText: 'Mobile Number',
        ),
    ),
like image 102
anmol.majhail Avatar answered Oct 20 '22 23:10

anmol.majhail


For others coming here who just want a TextField with a border all around it:

TextField(
  decoration: InputDecoration(
    border: OutlineInputBorder(),
  ),
),
like image 11
Suragch Avatar answered Oct 21 '22 01:10

Suragch