作者:mobiledu2502876651 | 来源:互联网 | 2023-09-05 18:06
Input控件是质感设计的文本输入控件,它在用户每次输入时都会调用onChanged回调时,都会更新字段值,还可以实时的对用户输入进行响应。
import 'package:flutter/material.dart';class MyApp extends StatefulWidget {@override_MyApp createState() => new _MyApp();
}class _MyApp extends State<MyApp> {InputValue _phoneValue &#61; const InputValue();InputValue _passwordValue &#61; const InputValue();void _showMessage(String name) {showDialog<Null>(context: context,child: new AlertDialog(content: new Text(name),actions: [new FlatButton(onPressed: () {Navigator.pop(context);},child: new Text(&#39;确定&#39;))]));}&#64;overrideWidget build(BuildContext context) {return new Scaffold(appBar: new AppBar(title: new Text(&#39;直接输入&#39;)),body: new Column(children: [new Input(value: _phoneValue,keyboardType: TextInputType.number,icon: new Icon(Icons.account_circle),labelText: &#39;手机&#39;,hintText: &#39;请输入手机号码&#39;,onChanged: (InputValue value) {setState((){_phoneValue &#61; value;});}),new Input(value: _passwordValue,obscureText: true,labelText: &#39;密码&#39;,onChanged: (InputValue value) {setState((){_passwordValue &#61; value;});},onSubmitted: (InputValue value) {if(value.text.length<6){_showMessage(&#39;密码不少于6位&#39;);}}),new RaisedButton(child: new Text(&#39;提交&#39;),onPressed: () {_showMessage(_phoneValue.text&#43;&#39;/&#39;&#43;_passwordValue.text);})]));}
}void main() {runApp(new MaterialApp(title: &#39;Flutter Demo&#39;,home: new MyApp()));
}