In this tutorial, we’ll learn how to properly customize Flutter textfield underline thickness by using practical Flutter code examples.
Outline
- Introduction: Flutter Textfield Underline Thickness
- Default Flutter Textfield Underline Thickness
- Change Flutter Textfield Underline Thickness (Multiple Examples)
- Custom Flutter Textfield Underline Thickness Source Code
- Conclusion
Introduction: Flutter Textfield Underline Thickness
It specifies the height of underline border. We’ll first see the default underline border thickness. After that, we’ll customize it practically.
Default Flutter Textfield Underline Thickness
For that, we’ve to implement a simple Flutter textfield widget. It comes with an underline border having default thickness. See below code:
TextField()
We can see default Flutter textfield underline thickness in the above image. Let’s now customize it.
Change Flutter Textfield Underline Thickness (Multiple Examples)
- We’ve to change the underline border thickness for both focused and enabled border, if we want both of them to have a custom underline border thickness.
- For that, we’ve to use the decoration constructor of Flutter textfield and pass it input decoration.
- After that, we’ve to pass underline input border to its enabled border constructor. Same process for focused border as well.
- Now we’ve to pass border side widget to its border side constructor.
- Finally, by using its width constructor, we can easily change Flutter textfield underline thickness. This constructor takes a double(decimal) value but passing it an integer will also work just fine.
- For demonstration, we’ll use multiple examples to show how it works. See below examples:
Example 1
TextField( decoration: InputDecoration( enabledBorder: UnderlineInputBorder( borderSide: BorderSide(width: 3) )), )
Example 2
enabledBorder: UnderlineInputBorder(borderSide: BorderSide(width: .3))
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(width: 3))
![How To Change Flutter Textfield Underline Thickness [Detailed Flutter Guide] 5 flutter textfield underline border thickness](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220927_073031-300x88.jpg)
So this is how we can easily change Flutter textfield underline thickness. You can specify different width values to enabled and focused border as well.
Custom Flutter Textfield Underline Thickness Source Code
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: TextField( decoration: InputDecoration( enabledBorder: UnderlineInputBorder(borderSide: BorderSide(width: 3.3)), focusedBorder: UnderlineInputBorder(borderSide: BorderSide(width: 3))), )), ))); } }
Conclusion
To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to customize Flutter textfield underline thickness. 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.
You might also like:
How To Change Flutter Textformfield Hint Text Weight [Easy Flutter Guide]
How To Set Flutter Carousel Slider Duration [Easy Flutter Code Examples]
How To Change Flutter Textfield Error Text Weight [Easy Flutter Guide]
How To Change Flutter Textfield Hint Text Weight [Easy Flutter Guide]
How To Change Flutter Textfield Error Text Size [Detailed Flutter Guide]
How To Change Flutter Textformfield Error Text Color [Detailed Flutter Guide]
How To Change Flutter Textfield Cursor Height – Easy Flutter Code Example
How To Easily Customize Flutter Appbar Back Button
How To Change Flutter Textfield Error Text Color [Detailed Flutter Guide]
How To Change Flutter Textformfield Focused Border Color [Easy Flutter Guide]
Flutter Textfield Onchanged Explained With Example-Best Flutter Guide
How To Change Flutter Textformfield Cursor Height – Easy Flutter Code Example