In this tutorial, we’ll learn how to properly set Flutter textformfield disable by using practical Flutter code example.
Introduction: Flutter Textformfield Disable
Disabling a textformfield is implemented when we don’t want our Flutter textformfield to take input from the user. It means that when the user tap on the Flutter textformfield which is disabled, he/she won’t be able to input anything in that disabled Flutter textformfield. Let’s now see how to achieve Flutter textformfield disable.
Implementing Flutter Textformfield Disable
Let’s now understand how to disable a Flutter textformfield using a proper Flutter code example. To make Flutter textformfield disable, you have to use the enabled constructor of the Flutter textformfield which takes a Boolean value. By default, it it true which means that user can give it inputs but we will make it false to achieve Flutter textformfield disable. See the below code:
TextFormField( enabled: false, )
![How To Set Flutter Textformfield Disable [Easy Flutter Code Example] 3 flutter textformfield disable](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220919_050823-300x88.jpg)
Flutter Textformfield Disable 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: TextFormField( enabled: false, ) )), )); } }
Conclusion
To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to implement Flutter textformfield disable. 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.