How To Change Flutter Textformfield Focused Outline Border Color

flutter textformfield focused outline border color

In this tutorial, we’ll learn how to properly change Flutter textformfield focused outline border color by using a practical Flutter code example.

Introduction: Flutter Textformfield Focused Outline Border Color

Focused border of textformfield is shown when the textformfield is focused/tapped. When we use outline border then it covers all the border sides of the textformfield.

Don’t worry, I will now implement it using proper example so you can have a better idea of what outline border is and how can we change Flutter textformfield focused outline border color.

Default Focused Outline Border Color

  • For that we have to implement a simple Flutter textformfield widget.
  • After that, we’ve to use the decoration constructor of the Flutter textformfield, then pass it input decoration class.
  • Finally, we’ve to pass the outline input border class to its focused border constructor. See the below code:
TextFormField(
           decoration: InputDecoration(
                  focusedBorder: OutlineInputBorder()
                ),
              )
flutter textformfield focused outline border default color
The default Flutter textformfield focused outline border color is shown in the above image.

Change Flutter Textformfield Focused Outline Border Color

For that we have to use the same process mentioned above and after that we have to use the border side constructor of the outline input border class and pass it the border side widget. Then by using the color constructor of border side class, we can change the color of the outline border of focused Flutter textformfield. See the below code:

focusedBorder: OutlineInputBorder(
                borderSide: BorderSide(color: Colors.green))
flutter textformfield focused outline border color
We can see that the outline border color of focused Flutter textformfield widget is now customized. Hope you like this post.
The complete source code of custom Flutter textformfield focused outline border color is given in the next section.

Custom Flutter Textformfield Focused Outline Border Color Source Code

flutter textformfield focused outline border color

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Homepage(),
    );
  }
}
class Homepage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
            body: Center(
                child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: 40),
                    child: TextFormField(
                      decoration: InputDecoration(
                          focusedBorder: OutlineInputBorder(
                              borderSide: BorderSide(color: Colors.green))),
                    )))));
  }
}

Conclusion

To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to change Flutter textformfield focused outline border color. I’d love to have your feedback on this post.

I’d also love to see you visit my other tutorials on Flutter app development and Python programming as well. Thank you for reading this post.

Leave a Comment

Your email address will not be published.