How To Set Flutter Textformfield Disable [Easy Flutter Code Example]

flutter textformfield disable

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,
         )
flutter textformfield disable
In the code above, you can see that we have set the enabled constructor of the Flutter textformfield to false which makes Flutter textformfield disable. You can test it yourself using this code and then tap on Flutter textformfield and you will see that the Flutter textformfield won’t get focused and you won’t be able to write anything in that disabled Flutter textformfield.
The complete source code in which Flutter textformfield is disabled is given in the next section.

Flutter Textformfield Disable Source Code

flutter textformfield disable

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.

Leave a Comment

Your email address will not be published.