If you want to create number input field in Flutter? Use the following code to create number input text box using Flutter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return new MaterialApp( home: new HomePage(), theme: new ThemeData(primarySwatch: Colors.blue), ); } } class HomePage extends StatefulWidget { @override State<StatefulWidget> createState() { return new HomePageState(); } } class HomePageState extends State<HomePage> { @override Widget build(BuildContext context) { return new Scaffold( backgroundColor: Colors.white, body: new Container( padding: const EdgeInsets.all(40.0), child: new Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ new TextField( decoration: new InputDecoration(labelText: "Enter your number"), keyboardType: TextInputType.number, inputFormatters: <TextInputFormatter>[ WhitelistingTextInputFormatter.digitsOnly ], // Only numbers can be entered ), ], )), ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.