国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Flutter質感設計之表單輸入

2019-10-21 21:40:25
字體:
來源:轉載
供稿:網友

FormField控件是單一表單字段,這個控件維護表單字段的當前狀態,以便更新和驗證錯誤能在UI中可見。TextField控件就是在FormField中包裝了一個Input控件(后面的文章講解),FormField維護輸入的當前值,使您不需要自己管理它,更容易一次保存,重置或驗證多個字段。

import 'package:flutter/material.dart';class MyApp extends StatefulWidget { @override _MyApp createState() => new _MyApp();}class _MyApp extends State<MyApp> { String _lastName; String _firstName; GlobalKey<FormState> _formKey = new GlobalKey<FormState>(); void _showMessage(String name) {  showDialog<Null>(   context: context,   child: new AlertDialog(    content: new Text(name),    actions: <Widget>[     new FlatButton(      onPressed: () {       Navigator.pop(context);      },      child: new Text('確定')     )    ]   )  ); } @override Widget build(BuildContext context) {  return new Scaffold(   appBar: new AppBar(    title: new Text('表單輸入')   ),   // Form:用于將多個表單控件組合在一起的容器   body: new Form(    key: _formKey,    child: new Column(     children: <Widget> [      // TextFieldd:包含輸入的表單控件,每個表單字段都應該在FormField控件中      new TextField(       labelText: '姓氏',       // onSaved:當通過Form.save()保存表單時調用的方法       onSaved: (InputValue value) {        _lastName = value.text;       }      ),      new TextField(       labelText: '名字',       onSaved: (InputValue value) {        _firstName = value.text;       }      ),      new Row(       children: <Widget> [        new RaisedButton(         child: new Text('重置'),         onPressed: () {          // reset():將此Form下的每個TextField重置為初始狀態          _formKey.currentState.reset();          _showMessage('姓名信息已經重置');         }        ),        new RaisedButton(         child: new Text('提交'),         onPressed: () {          // save():保存Form下的每個TextField          _formKey.currentState.save();          _showMessage('你的姓名是'+_lastName+_firstName);         }        )       ]      )     ]    )   )  ); }}void main() { runApp(new MaterialApp(  title: 'Flutter Demo',  home: new MyApp() ));}

Flutter,質感設計,表單輸入

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南华县| 莱西市| 弥渡县| 永济市| 陕西省| 普安县| 越西县| 南昌县| 油尖旺区| 西盟| 霞浦县| 绥宁县| 库伦旗| 东乌珠穆沁旗| 沐川县| 大新县| 启东市| 满城县| 漯河市| 永定县| 武清区| 延津县| 扎鲁特旗| 玛沁县| 永靖县| 桃园县| 贞丰县| 姚安县| 克山县| 门头沟区| 蓝田县| 衡水市| 五指山市| 长沙市| 阿坝| 大同市| 右玉县| 平顶山市| 渑池县| 凌云县| 方山县|