{"id":1152,"date":"2023-03-16T22:10:49","date_gmt":"2023-03-16T14:10:49","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1152"},"modified":"2023-03-16T22:10:56","modified_gmt":"2023-03-16T14:10:56","slug":"flutter-widget-checkbox","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/16\/flutter-widget-checkbox\/","title":{"rendered":"Flutter Widget\u4e4bCheckbox"},"content":{"rendered":"<p>Widget\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/flutter.io\/docs\/development\/ui\/widgets\">https:\/\/flutter.io\/docs\/development\/ui\/widgets<\/a><br \/>\nCheckbox\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/docs.flutter.io\/flutter\/material\/Checkbox-class.html\">https:\/\/docs.flutter.io\/flutter\/material\/Checkbox-class.html<\/a><br \/>\n\u00a0 \u00a0 \u00a0 <\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-dart\">import &#039;package:flutter\/material.dart&#039;;\n\nclass CheckBoxDemoPage extends StatefulWidget {\n  @override\n  State&lt;StatefulWidget&gt; createState() {\n    return new _CheckBoxDemoPageState();\n  }\n}\n\nclass _CheckBoxDemoPageState extends State&lt;CheckBoxDemoPage&gt; {\n  bool isCheck = false;\n  List&lt;bool&gt; isChecks = [false, false];\n\n  @override\n  Widget build(BuildContext context) {\n    return new Scaffold(\n      appBar: AppBar(\n        title: Text(&#039;CheckBox Demo&#039;),\n      ),\n      body: new Column(\n        mainAxisAlignment: MainAxisAlignment.start,\n        children: &lt;Widget&gt;[\n          new Center(\n            child: new Checkbox(\n              value: isCheck,\n              activeColor: Colors.red,\n              onChanged: (bool) {\n                setState(() {\n                  isCheck = bool;\n                });\n              },\n            ),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isCheck,\n                title: new Text(&#039;Joe.Ye&#039;),\n                controlAffinity: ListTileControlAffinity.platform,\n                \/\/\u63a7\u5236\u4eb2\u548c\u5ea6: leading\u6309\u94ae\u663e\u793a\u5728\u6587\u5b57\u524d\u9762, trailing\u6309\u94ae\u663e\u793a\u5728\u6587\u5b57\u7684\u540e\u9762, platform\u663e\u793a\u6837\u5f0f\u6839\u636e\u624b\u673a\u5f53\u524d\u5e73\u53f0\u9ed8\u8ba4\u663e\u793a\n                onChanged: (bool) {\n                  setState(() {\n                    isCheck = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isCheck,\n                title: new Text(&#039;Joe.Ye&#039;),\n                secondary: const Icon(Icons.access_alarm),\n                controlAffinity: ListTileControlAffinity.platform,\n                onChanged: (bool) {\n                  setState(() {\n                    isCheck = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isCheck,\n                title: new Text(&#039;Joe.Ye&#039;),\n                controlAffinity: ListTileControlAffinity.leading,\n                onChanged: (bool) {\n                  setState(() {\n                    isCheck = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isCheck,\n                title: new Text(&#039;AppBlog.CN&#039;),\n                controlAffinity: ListTileControlAffinity.trailing,\n                onChanged: (bool) {\n                  setState(() {\n                    isCheck = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isCheck,\n                title: new Text(&#039;http:\/\/www.appblog.cn&#039;),\n                controlAffinity: ListTileControlAffinity.platform,\n                onChanged: (bool) {\n                  setState(() {\n                    isCheck = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isChecks[0],\n                title: new Text(&#039;Android&#039;),\n                controlAffinity: ListTileControlAffinity.platform,\n                onChanged: (bool) {\n                  setState(() {\n                    isChecks[0] = bool;\n                  });\n                }),\n          ),\n          new Center(\n            child: new CheckboxListTile(\n                value: isChecks[1],\n                title: new Text(&#039;iOS&#039;),\n                controlAffinity: ListTileControlAffinity.platform,\n                onChanged: (bool) {\n                  setState(() {\n                    isChecks[1] = bool;\n                  });\n                }),\n          )\n        ],\n      )\n    );\n  }\n}<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/www.yezhou.me\/AppBlog\/images\/Flutter\/Flutter_Widget_Checkbox.png\" alt=\"Flutter Widget Checkbox\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Widget\uff1ahttps:\/\/flutter.io\/docs\/development\/ui\/widgets C [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[305],"class_list":["post-1152","post","type-post","status-publish","format-standard","hentry","category-flutter","tag-flutter-widget"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1152"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1152\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}