美文网首页
flutter控件之CheckBox

flutter控件之CheckBox

作者: Mr丶xi先森 | 来源:发表于2018-09-11 16:03 被阅读1147次
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;
                  });
                }),
          )
        ],
      )
    );
  }
}

相关文章

网友评论

      本文标题:flutter控件之CheckBox

      本文链接:https://www.haomeiwen.com/subject/cspugftx.html