How to Disable Keyboard Popup on TextField in Flutter

This example shows you how to disable the keyboard popup when TextField or TextFormField is clicked. You may need to disable the keyboard popup in many conditions such as when using a custom keyboard, your own designed keyword, or others. See the example below and learn how to disable the keyboard popup on textfield. 

TextField(
  keyboardType: TextInputType.none,
)

You do not need anything complex or huge to disable the keyboard popup on textfield, you just need to change the keyboard type of textfield to none using the above code. 

OR, you can also use the following code to disable the keyboard popup TextField. 

TextField(
  showCursor: true,
  readOnly: true
),

import 'package:flutter/material.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget{
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {  
  @override
  Widget build(BuildContext context) { 
    return  Scaffold(
          appBar: AppBar(
            title: Text("Disable Keyboard Popup on TextField"),
            backgroundColor: Colors.redAccent
          ),
          
          body: Container(
              child: Column(
                 children: [
                     TextField(
                        keyboardType: TextInputType.none,
                     ),

                     TextFormField(
                        showCursor: true,
                        readOnly: true,
                     )
                 ],
              )
          )
       );
  }
}

In this way, you can disable the keyboard popup on TextField or TextFormField when clicked in Flutter.

No any Comments on this Article


Please Wait...