flutter控件之CheckBox

import 'package:flutter/material.dart'; class LearnCheckBox extends StatefulWidget{ @override State<StatefulWidget> createState() { return new _LearnCheckBox(); } } class _LearnCheckBox extends State<LearnCheckBox>{ bool isCheck=false; List<bool> isChecks=[false,false]; @override Widget build(BuildContext context) { return new Scaffold( body:new Column( mainAxisAlignment: MainAxisAlignment.start, children: <Widget>[ new Center( child: new Checkbox( value: isCheck, activeColor: Colors.red, onChanged: (bool){ setState(() { isCheck=bool; }); }, ), ), new Center( child: new CheckboxListTile( value: isCheck, title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform,//控制親和度 leading按鈕顯示在文字前面 trailing按鈕顯示在文字的後面 platform顯示樣式根據手機當前平臺默認顯示
                onChanged: (bool){ setState(() { isCheck=bool; }); }), ), new Center( child: new CheckboxListTile( value: isCheck, title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isCheck=bool; }); }), ), new Center( child: new CheckboxListTile( value: isCheck, title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isCheck=bool; }); }), ), new Center( child: new CheckboxListTile( value: isCheck, title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isCheck=bool; }); }), ), new Center( child: new CheckboxListTile( value: isCheck, title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isCheck=bool; }); }), ), new Center( child: new CheckboxListTile( value: isChecks[0], title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isChecks[0]=bool; }); }), ), new Center( child: new CheckboxListTile( value: isChecks[1], title: new Text('張曉'), controlAffinity: ListTileControlAffinity.platform, onChanged: (bool){ setState(() { isChecks[1]=bool; }); }), ) ], ) ); } }
相關文章
相關標籤/搜索