ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
![](https://img.kancloud.cn/04/50/0450a1369848d61dfb892f5d1985309f_848x1094.png) ***** ``` ~~~ import 'package:flutter/material.dart'; class FormDemoPage extends StatefulWidget { @override _FormDemoPageState createState() => _FormDemoPageState(); } class _FormDemoPageState extends State<FormDemoPage> { String username; int sex = 1; List hobby = [ { "checked" : false, "title":"吃饭" }, { "checked" : true, "title":"写代码" }, { "checked" : true, "title":"购物" }, ]; List<Widget> _getHobby(){ List<Widget> l = []; for(var i = 0; i < this.hobby.length; i++){ l.add( Text(this.hobby[i]["title"] + ":")); l.add( Checkbox( value: this.hobby[i]["checked"], onChanged: (v){ setState(() { this.hobby[i]["checked"] = v; }); } ) ); } return l; } void _setSexChanged(v){ setState(() { this.sex = v; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("登记"), ), body: Padding( padding: EdgeInsets.all(20), child: Column( children: <Widget>[ TextField( decoration: InputDecoration( hintText: "请输入用户姓名", ), onChanged: (v){ setState(() { this.username = v; }); }, ), Row( children: <Widget>[ Text("男"), Radio( value: 1, groupValue: this.sex, onChanged: _setSexChanged, ), SizedBox(width: 20), Text("女"), Radio( value: 2, groupValue: this.sex, onChanged: _setSexChanged ), ], ), SizedBox(height: 20,), SizedBox(height: 20), Column( children: this._getHobby(), ), Container( width: double.infinity, height: 40, child:RaisedButton( color: Colors.blue, textColor: Colors.white, child: Text("登陆"), onPressed: (){ print(this.username); print(this.sex); print(this.hobby); } ), ), ], ), ), ); } } ~~~ ```