如何在Flutter中创建数字输入字段?

如何在Flutter中创建数字输入字段?,第1张

如何在Flutter中创建数字输入字段

您可以使用以下命令将数字指定
keyboardType
for the TextField using:

keyboardType: TextInputType.number

检查我的main.dart文件

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          ),        ],      )),    );  }}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5082995.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存