In this tutorial, we’ll learn how to properly customize Flutter textfield keyboardType by using practical Flutter code examples.
What is Flutter Textfield KeyboardType?
As the name suggests, it specifies the keyboard type that popup whenever a Flutter textfield is tapped or focused. Customizing keyboard type of Flutter textfield means that we can set whether we want to see only numbers or other type of keyboard etc. Let’s start understanding it using a proper example code.
Default Flutter Textfield KeyboardType
First we will see what the default Flutter textfield keyboardtype is. For that we have to implement a Flutter textfield and taps on it so the keyboard can appear. See the below code for this:
TextField()
![How To Customize Flutter Textfield KeyboardType [Easy Explanation] 3 flutter textfield default keyboard type](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220917_234605-215x300.jpg)
Changing Flutter Textfield KeyboardType
Let’s now change the Flutter textfield keyboardtype. For that, you have to use the keyboard type constructor of the Flutter textfield, it takes a text input type class and using its properties, we can specify the type of keyboard that we want to show when the user clicks on Flutter textfield.
Let’s specify Flutter textfield keyboardtype to only take numbers. For that you have to use the number property of the text input type class which is implemented in the below code:
keyboardType: TextInputType.number,
![How To Customize Flutter Textfield KeyboardType [Easy Explanation] 4 flutter textfield keyboard type number](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220917_234650-223x300.jpg)
For phone
keyboardType: TextInputType.phone
![How To Customize Flutter Textfield KeyboardType [Easy Explanation] 5 flutter textfield keyboard type phone](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220917_234726-227x300.jpg)
For Email Address
keyboardType: TextInputType.emailAddress
![How To Customize Flutter Textfield KeyboardType [Easy Explanation] 6 flutter textfield keyboard type email address](https://letmeflutter.com/wp-content/uploads/2022/09/IMG_20220917_234758-217x300.jpg)
Custom Flutter Textfield KeyboardType 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 StatelessWidget { @override Widget build(BuildContext context) { return SafeArea( child: Scaffold( body: Center( child: Padding( padding: EdgeInsets.symmetric(horizontal: 40), child: TextField( keyboardType: TextInputType.emailAddress, ))), )); } }
Conclusion
To conclude this tutorial, now you’ve a detailed and in-depth practical knowledge of how to customize Flutter textfield keyboardType. 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.