Solved: How to create number input field in Flutter?


Asked by Janne A on March 30, 2018 (source).

I'm unable to find a way to create an input field in Flutter that would open up a numeric keyboard. Is this possible with Flutter material widgets? Some github discussions seem to indicate this is a supported feature but I'm unable to find any documentation about it.


Question answered by Rissmon S (source).

You can specify the number as keyboardType for the TextField using:

keyboardType: TextInputType.number

Check my main.dart file

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      home: new HomePage(),
      theme: new ThemeData(primarySwatch:,

class HomePage extends StatefulWidget {
  State<StatefulWidget> createState() {
    return new HomePageState();

class HomePageState extends State<HomePage> {
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colors.white,
      body: new Container(
          padding: const EdgeInsets.all(40.0),
          child: new Column(
        children: <Widget>[
          new TextField(
            decoration: new InputDecoration(labelText: "Enter your number"),
            keyboardType: TextInputType.number,
            inputFormatters: <TextInputFormatter>[
], // Only numbers can be entered

enter image description here