How to Change Keyboard Type Input on TextField in Flutter

In this exampe, we are going to show you the way to change the keyboard input type in TextField widget in Flutter App. You can set to email address, number, URL, name, street address input keyboard according to the data type of TextField widget.

TextField( 
  keyboardType: TextInputType.number,
)

TextField( 
  keyboardType: TextInputType.emailAddress,
)

TextField( 
  keyboardType: TextInputType.datetime,
)

TextField( 
  keyboardType: TextInputType.phone,
)

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> {

  TextEditingController myinput = TextEditingController();
  @override
  void initState() {
    myinput.text = ""; //innitail value of text field
    super.initState();
  }
  
  @override
  Widget build(BuildContext context) {
    return  Scaffold(
          appBar: AppBar( 
             title: Text("Keyboard Type on TextField"),
             backgroundColor: Colors.deepOrangeAccent,
          ),
          body: Container(
            padding: EdgeInsets.all(20),
            child: Center( 
              child: TextField( 
                controller: myinput,
                keyboardType: TextInputType.phone,
              ),
            ),
          )
       );
  }
}

In this way, you can change the keyboard type input on TextField() widget on Flutter App. 

 

No any Comments on this Article


Please Wait...