当前位置:网站首页>浅识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, //浮标的位置
);
}
}
边栏推荐
猜你喜欢
12 Disk related commands
7年经验,功能测试工程师该如何一步步提升自己的能力呢?
【动态规划】连续子数组的最大和
CorelDRAW2022 streamlined Asia Pacific new features in detail
Graphical lower_bound & upper_bound
Detailed explanation of TCP (2)
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
接口测试关键技术
【C语言】三子棋(经典解法+一览图)
Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
随机推荐
WebSocket Session为null
TCP和UDP详解
遗留系统的自动化策略
Ambiguous method call.both
分布式系统架构需要解决的问题
Several common errors when using MP
Ambiguous method call.both
SQALE 是什么
Automation strategies for legacy systems
Moxa NPort device flaw could expose critical infrastructure to devastating attack
LeetCode中等题之分数加减运算
Office automation case: how to automatically generate period data?
TCP/IP four-layer model
12 Disk related commands
The distance value between two arrays of LeetCode simple questions
SQL injection Less46 (injection after order by + rand() Boolean blind injection)
8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
数据库实现分布式锁
Thesis framework of the opening report
10 Permission introduction