Checkbox

基本属性

  1. const Checkbox({
  2. Key key,
  3. @required this.value, // true 选中,false非选中
  4. this.tristate = false, // 如果为真,复选框的[value]可以为真、假或空。复选框的值为空时显示破折号。当一个三态复选框([tristate]为真)被点击时,如果当前值为假,它的[onChanged]回调将被应用到true,如果值为真,将被应用到null,如果值为空,
  5. @required this.onChanged, // 点击事件
  6. this.activeColor, // 为激活状态下颜色,是矩形区域内的颜色
  7. this.checkColor, // 是选中后“对勾”的颜色,用法如下:
  8. this.focusColor,
  9. this.hoverColor,
  10. this.materialTapTargetSize,
  11. this.visualDensity,
  12. this.focusNode,
  13. this.autofocus = false,
  14. }) : assert(tristate != null),
  15. assert(tristate || value != null),
  16. assert(autofocus != null),
  17. super(key: key);

基本用法

  1. Checkbox(
  2. value: _checkbox,
  3. tristate: true,
  4. activeColor: Colors.yellow[700],
  5. checkColor: Colors.black,
  6. onChanged: (e){
  7. print("$e, $_checkbox");
  8. setState(() {
  9. _checkbox = e;
  10. });
  11. },
  12. ),

image.pngimage.pngimage.png

CheckboxList

基本属性

  1. const CheckboxListTile({
  2. Key key,
  3. @required this.value,
  4. @required this.onChanged,
  5. this.activeColor,
  6. this.checkColor,
  7. this.title, // 主标题
  8. this.subtitle, // 副标题
  9. this.isThreeLine = false,
  10. this.dense,
  11. this.secondary, // 将显示在复选框平铺的另一侧的小部件。
  12. this.selected = false,
  13. this.controlAffinity = ListTileControlAffinity.platform,
  14. }) : assert(value != null),
  15. assert(isThreeLine != null),
  16. assert(!isThreeLine || subtitle != null),
  17. assert(selected != null),
  18. assert(controlAffinity != null),
  19. super(key: key);

基本用法

  1. List <Map>_checkbox = [
  2. {
  3. "title" : "国庆倒计时",
  4. "subTitle" : "剩余天数 3天",
  5. "isActive" : false,
  6. "Icon" : 0xe6b2
  7. },
  8. {
  9. "title" : "中秋倒计时",
  10. "subTitle" : "剩余天数 3天",
  11. "isActive" : false,
  12. "Icon" : 0xe6d9
  13. },
  14. {
  15. "title" : "元旦倒计时",
  16. "subTitle" : "剩余天数 90天",
  17. "isActive" : false,
  18. "Icon" : 0xe6ef
  19. },
  20. {
  21. "title" : "除夕倒计时",
  22. "subTitle" : "剩余天数 146",
  23. "isActive" : false,
  24. "Icon" : 0xe6ef
  25. }
  26. ];
  27. body: Column(
  28. children : <Widget>[
  29. for(num i = 0 ; i < _checkbox.length ; i ++)
  30. CheckboxListTile(
  31. title: Text( _checkbox[i]['title'] ) ,
  32. subtitle: Text( _checkbox[i]['subTitle'] ),
  33. secondary: Icon(
  34. IconData(
  35. _checkbox[i]['Icon'],
  36. fontFamily : 'wz'
  37. ),
  38. textDirection : TextDirection.ltr ,
  39. size: 33,
  40. color: Colors.yellow[700],
  41. ),
  42. value: _checkbox[i]['isActive'],
  43. onChanged: (e){
  44. setState(() {
  45. _checkbox[i]['isActive'] = e;
  46. });
  47. },
  48. ),
  49. ]
  50. ),

image.png