How to change the border color of a Textformfield?

Asked

Viewed 3,112 times

3

I would like to change the color of the Textformfield border on the login screen to white, because the background is gradient and it would be easier to view the text. Today I’m using the pattern I created for the theme:

ThemeData buildTheme() {
  final ThemeData base = ThemeData();

  return base.copyWith(
    primaryColor: Colors.lightBlue,
    inputDecorationTheme: InputDecorationTheme(
      border: OutlineInputBorder(),
    ),
  );
}

And I tried to create a decoration in the field:

final password = TextFormField(
  autofocus: false,
  obscureText: true,
  decoration: InputDecoration(
    labelText: 'Senha',
    border: OutlineInputBorder(
      borderSide: BorderSide(
        color: Colors.white,
      ),
    )
  ),
);

But I did not succeed. How can I do this only for the fields on this screen?

3 answers

2


To solve this problem I created a new theme for the TextFormField in question:

final password = new Theme(
  data: new ThemeData(
    hintColor: Colors.white,
  ),
  child: TextFormField(
    autofocus: false,
    obscureText: true,
    decoration: InputDecoration(
      labelText: 'Senha',
      border: OutlineInputBorder(),
    ),
  ),
);

0

or Voce can disable the border simply by using enabledBorder: Inputborder.None inside the Inputdecoration ex:

TextFormField(
 decoration: InputDecoration(
 labelText: 'Email',
 enabledBorder: InputBorder.none,// isso que vc quer para desativar a borda
 labelStyle: TextStyle(
 color: Colors.white,
 fontSize: 15.0,
  ),
 ),
),

-1

You have to do it for Main.dart

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Dog Life',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.purple,
        
      ),
      home: LoginPage(),
    );
  }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.