class DemoPage extends StatefulWidget { DemoPage({Key key}) : super(key: key); @override _DemoPageState createState() => _DemoPageState(); } class _DemoPageState extends State<DemoPage> { var currentIndex = 0; @override Widget build(BuildContext context) { return Column( children: [ Checkbox( //激活时的颜色 activeColor: Colors.red, //是否被选中 value: 0 == currentIndex, //复选框是否有空值,如果为true,则有true、false和空三个值,false则只有true和false两个值 tristate: false, onChanged: (bool check) { setState(() { if (check) { currentIndex = 0; } }); }), Checkbox( //激活时的颜色 activeColor: Colors.red, //是否被选中 value: 1 == currentIndex, onChanged: (bool check) { setState(() { if (check) { currentIndex = 1; } }); }), ], ); } }
部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!