In this tutorial, we’ll learn how to easily implement Flutter textformfield label by using a proper practical Flutter example code.
Introduction: Flutter Textformfield Label
Flutter textformfield label can be used to describe the input Flutter textformfield. When the Flutter textformield is unfocused or empty then the Flutter textformfield label is shown where the input from user will be taken, means at the same position where the entered input will be shown but when the Flutter textformfield is focused then it animates to the top left position of the Flutter textformfield.
Flutter textformfield label takes a widget means we can pass multiple Flutter text widgets to it or other Flutter widgets like Flutter containers etc. Flutter textformfield label can be used to give more decoration to the Flutter textformfield. Let’s now implement it using a proper Flutter code to have a better understanding of how Flutter textformfield label works.
Implementing Flutter Textformfield Label
Now to implement Flutter textformfield label, we have to use the label constructor of the input decoration class. Let’s see the below code for this:
label: Row( children: [ Icon( Icons.phone, color: Colors.grey, ), SizedBox( width: 5, ), Text( 'Enter phone number', ), ], ),



Custom Flutter Textformfield Complete 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 StatefulWidget { @override State<Homepage> createState() => _HomepageState(); } class _HomepageState extends State<Homepage> { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( body: Center( child: Padding( padding: EdgeInsets.symmetric(horizontal: 40), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ TextFormField( style: TextStyle(color: Colors.blue), cursorColor: Colors.blue, decoration: InputDecoration( border: InputBorder.none, filled: true, fillColor: Colors.blue.withOpacity(.08), contentPadding: EdgeInsets.all(26), label: Row( mainAxisSize: MainAxisSize.min, children: [ Icon( Icons.home, color: Colors.blue, ), SizedBox( width: 5, ), Text( 'Enter your address', style: TextStyle( color: Colors.blue.withOpacity(.6)), ), ], ), enabledBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue), borderRadius: BorderRadius.circular(30).copyWith( topRight: Radius.circular(0), topLeft: Radius.circular(0))), focusedBorder: OutlineInputBorder( borderSide: BorderSide(color: Colors.blue), borderRadius: BorderRadius.circular(30).copyWith( topRight: Radius.circular(0), topLeft: Radius.circular(0)))), ) ], ))), )); } }
Conclusion
To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to customize Flutter textformfield label. I’ll be delighted to receive your feedback on this post.
I’d love to see you visit my other tutorials on Flutter app development and Python programming as well. Thank you for reading this post.