88

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.

Little Monkey
  • 5,395
  • 14
  • 45
  • 83
  • Not exactly answer to your question but just to add border to TextField this works: `TextField(decoration: InputDecoration(border: OutlineInputBorder(borderSide: BorderSide(),),),);` More at: https://api.flutter.dev/flutter/material/OutlineInputBorder-class.html – user3563059 Feb 13 '20 at 07:38

5 Answers5

223

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',
        ),
    ),
cokeman19
  • 2,405
  • 1
  • 25
  • 40
anmol.majhail
  • 48,256
  • 14
  • 136
  • 105
16

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

TextField(
  decoration: InputDecoration(
    border: OutlineInputBorder(),
  ),
),
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
8

You can change the outlined variant of TextField or TextFormField globally by overriding the ThemeData at the top level:

return MaterialApp(
  theme: ThemeData(
    inputDecorationTheme: const InputDecorationTheme(border: OutlineInputBorder()),
  ),
)

Live Demo

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
0

I'm using this one and it is working for me.

InputDecoration(
    focusedBorder: OutlineInputBorder(
      borderRadius:
          BorderRadius.circular(16),
      borderSide: const BorderSide(color: Colors.black, width: 2.5),
    ),
    enabledBorder: OutlineInputBorder(
      borderRadius:
          BorderRadius.circular(16),
      borderSide: const BorderSide(color:Colors.black, width: 1.5),
    ),
  )
0

I'm using this one and it is working for me.

child: TextField(
                    decoration: InputDecoration(
                      hintText: "Email Address",
                      hintStyle: TextStyle(color: Colors.grey),
                      focusedBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.black, width: 1),
                      ),
                      enabledBorder: OutlineInputBorder(
                        borderSide: BorderSide(color: Colors.black, width: 1),
                      ),
                    ),
                  ),