当前位置:网站首页>浅识Flutter 基本组件之CheckBox组件
浅识Flutter 基本组件之CheckBox组件
2022-07-31 03:12:00 【阿大豆】
浅识Flutter 基本组件之CheckBox组件
常用属性如下表所示
| 属性名 | 类型 | 功能说明 |
|---|---|---|
| value | bool | 设置复选框是否选中,取值包括true(选中) 、 false (没选中) |
| onChanged | 设置监听复选框的值发生改变时回调 | |
| tristate | bool | 设置复选框是否三态,取值包括true、false和 null |
| activeColor | Color | 设置复选框选中时的颜色 |
| checkColor | Color | 设置复选框选中时选中图标()的颜色 |
| materialTapTargetSize | double | 设置点击目标的大小,取值默包括 padded、shrink Wrap两种 |
Checkbox(value: flag,onChanged: (value){
//setState更新值
setState(() {
flag=value!;
});
},) ,

选中后
实现横排多个选项
body: Row(
children: <Widget>[
Text('选择你的阵营: '),
Text(select[0]),
Checkbox(
value: flag[0],
onChanged: (value) {
//setState更新值
setState(() {
flag[0] = value!;
});
},
),
Text(select[1]),
Checkbox(
value: flag[1],
onChanged: (value) {
//setState更新值
setState(() {
flag[1] = value!;
});
},
),
Text(select[2]),
Checkbox(
value: flag[2],
onChanged: (value) {
//setState更新值
setState(() {
flag[2] = value!;
});
},
),
],
),

选择选项后,将选择的对象打印出来
floatingActionButton: FloatingActionButton(
onPressed: () {
String info="你选择的阵营是:";
for(int i=0;i<flag.length;i++){
if(flag[i]) {
/*如果选项被选中*/
info = info + select[i]+' ';
}
}print(info);
},
tooltip: 'Increment',
child: Icon(Icons.save),
),

完整代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class zhucepage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return MyState();
}
}
class MyState extends State {
List flag =[false,false,false] ;
List select=['皇后','华妃','甄嬛'];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('用户注册'),
centerTitle: true,
),
body: Row(
children: <Widget>[
Text('选择你的阵营: '),
Text(select[0]),
Checkbox(
value: flag[0],
onChanged: (value) {
//setState更新值
setState(() {
flag[0] = value!;
});
},
),
Text(select[1]),
Checkbox(
value: flag[1],
onChanged: (value) {
//setState更新值
setState(() {
flag[1] = value!;
});
},
),
Text(select[2]),
Checkbox(
value: flag[2],
onChanged: (value) {
//setState更新值
setState(() {
flag[2] = value!;
});
},
),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
String info="你选择的阵营是:";
for(int i=0;i<flag.length;i++){
if(flag[i]) {
/*如果选项被选中*/
info = info + select[i]+' ';
}
}print(info);
},
tooltip: 'Increment',
child: Icon(Icons.save),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endTop, //浮标的位置
);
}
}
边栏推荐
- TCP/IP four-layer model
- 7. List of private messages
- 6. Display comments and replies
- 数据库实现分布式锁
- 【Cocos Creator 3.5】缓动系统停止所有动画
- CloudCompare&PCL 计算两个点云之间的重叠度
- [C language] Preprocessing operation
- IDEA 注释报红解决
- JS function this context runtime syntax parentheses array IIFE timer delay self.backup context call apply
- 注解用法含义
猜你喜欢
随机推荐
华为分布式存储FusionStorage知识点总结【面试篇】
Graphical lower_bound & upper_bound
Difference between unallocated blocks and unused blocks in database files
CorelDRAW2022 streamlined Asia Pacific new features in detail
大小端模式
IIR滤波器和FIR滤波器
Good place to download jar packages
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
Map.Entry理解和应用
7年经验,功能测试工程师该如何一步步提升自己的能力呢?
Ambiguous method call.both
数据库实现分布式锁
编译Hudi
Use of QML
Multilingual settings of php website (IP address distinguishes domestic and foreign)
Unity3D Button mouse hover enter and mouse hover exit button events
什么是分布式锁?实现分布式锁的三种方式
What is distributed and clustered?What is the difference?
Key Technologies of Interface Testing
els 方块向右移动边界判断、向下加速
![[C language] Preprocessing operation](/img/69/0aef065ae4061edaf0d96b89846bf2.png)







