当前位置:网站首页>浅识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, //浮标的位置
);
}
}
边栏推荐
- How to build a private yum source
- 递归查询单表-单表树结构-(自用)
- What is a distributed lock?Three ways of implementing distributed lock
- Graphical lower_bound & upper_bound
- 【Cocos Creator 3.5】缓动系统停止所有动画
- 【HCIP】ISIS
- 【HCIP】ISIS
- Software accumulation -- Screenshot software ScreenToGif
- SocialFi 何以成就 Web3 去中心化社交未来
- Several common errors when using MP
猜你喜欢

Graphical lower_bound & upper_bound

华为分布式存储FusionStorage知识点总结【面试篇】

Discourse Custom Header Links

Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢

Detailed explanation of TCP (1)
![[Compilation principle] Design principle and implementation of recursive descent parsing](/img/51/cd054a8246dc108520d6ff9ea26c60.png)
[Compilation principle] Design principle and implementation of recursive descent parsing

10 Permission introduction

【C语言】表达式求值的一般方法

IDEA comment report red solution
![[Compilation principle] Lexical analysis program design principle and implementation](/img/eb/035234a402edf18beb7e2f82ebec17.png)
[Compilation principle] Lexical analysis program design principle and implementation
随机推荐
分布式系统架构需要解决的问题
Unity3D Button mouse hover enter and mouse hover exit button events
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
The Map Entry understanding and application
execsnoop tool
LeetCode简单题之两个数组间的距离值
【Exception】The field file exceeds its maximum permitted size of 1048576 bytes.
6. Display comments and replies
数据库实现分布式锁
Discourse Custom Header Links
Observer pattern
【编译原理】递归下降语法分析设计原理与实现
SQL injection Less47 (error injection) and Less49 (time blind injection)
Automation strategies for legacy systems
SQALE 是什么
PMP微信群日常习题
How to build a private yum source
False positives and false negatives in testing are equally worthy of repeated corrections
Redis implements distributed locks
11. Redis implements follow, unfollow, and follow and follower lists