import 'package:flutter/material.dart'; class TextFieldDemoPage extends StatefulWidget { TextFieldDemoPage({Key key}) : super(key: key); _TextFieldDemoPageState createState() => _TextFieldDemoPageState(); } class _TextFieldDemoPageState extends State<TextFieldDemoPage> { var _username=new TextEditingController(); //初始化的时候,给表单赋值: var _password; @override void initState(){ super.initState(); _username.text="初始值"; } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('表单演示页面'), ), body: Padding( padding: EdgeInsets.all(20), child: Column( children: <Widget>[ // TextField(), // SizedBox(height: 20), // TextField( // decoration: InputDecoration( // hintText: "请输入搜索的内容", // border: OutlineInputBorder() // ), // ), // SizedBox(height: 20), // TextField( //设置为多行文本框: // maxLines: 4, // decoration: InputDecoration( // hintText: "多行文本框", // border: OutlineInputBorder() // ), // ), // SizedBox(height: 20), // TextField( // obscureText: true, //把文本框修改成密码框: // decoration: InputDecoration( // hintText: "密码框", // border: OutlineInputBorder() // ), // ), // SizedBox(height: 20), // TextField( // obscureText: true, // decoration: InputDecoration( // hintText: "labelText使用", // border: OutlineInputBorder(), // labelText: "用户名" // ), // ), TextDemo(), TextField( obscureText: true, decoration: InputDecoration( hintText: "labelText使用", border: OutlineInputBorder(), labelText: "密码"), onChanged: (value){ setState(() { this._password=value; }); }, ), TextField( decoration: InputDecoration(icon: Icon(Icons.search), hintText: "请输入用户名"), controller: _username, onChanged: (value){ setState(() { _username.text=value; }); }, ), Container( width: double.infinity, height: 40, child: RaisedButton( child: Text("登录"), onPressed: (){ print(this._username.text); print(this._password); }, color: Colors.blue, textColor: Colors.white, ), ) ], ), ), ); } } class TextDemo extends StatelessWidget { const TextDemo({Key key}) : super(key: key); @override Widget build(BuildContext context) { return Container( child: TextField( decoration: InputDecoration(icon: Icon(Icons.people), hintText: "请输入用户名"), ), ); } }
CheckBox.dart
import 'package:flutter/material.dart'; class CheckBoxDemoPage extends StatefulWidget { CheckBoxDemoPage({Key key}) : super(key: key); _CheckBoxDemoPageState createState() => _CheckBoxDemoPageState(); } // CheckBox class _CheckBoxDemoPageState extends State<CheckBoxDemoPage> { var flag=true; @override Widget build(BuildContext context) { return Scaffold( appBar:AppBar( title: Text('CheckBox'), ), body:Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Row( children: <Widget>[ Checkbox( value: this.flag, onChanged: (v){ setState(() { this.flag=v; }); }, activeColor: Colors.red, ) ], ), Row( children: <Widget>[ Text(this.flag?'选中':'未选中') ], ), SizedBox(height: 40), CheckboxListTile( value: this.flag, onChanged: (v){ setState(() { this.flag=v; }); }, title: Text('标题'), subtitle: Text('这是一个二级标题'), secondary: Icon(Icons.help), ) ], ) ); } }