当前位置:网站首页>浅识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, //浮标的位置
);
}
}
边栏推荐
- Moxa NPort device flaw could expose critical infrastructure to devastating attack
- How to develop a high-quality test case?
- Installation of mysql5.7.37 under CentOS7 [perfect solution]
- Unity3D Button mouse hover enter and mouse hover exit button events
- 观察者模式
- 一份高质量的测试用例如何养成?
- YOLOV5 study notes (2) - environment installation + operation + training
- SQL injection Less46 (injection after order by + rand() Boolean blind injection)
- [Android] Room - Alternative to SQLite
- Mysql 45讲学习笔记(二十三)MYSQL怎么保证数据不丢
猜你喜欢

【编译原理】词法分析程序设计原理与实现

CefSharp入门-winform

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

Recursive query single table - single table tree structure - (self-use)

10 Permission introduction

【动态规划】连续子数组的最大和

【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法

VS QT - ui does not display newly added members (controls) || code is silent

LeetCode简单题之找到和最大的长度为 K 的子序列

8. Unified exception handling (controller notifies @ControllerAdvice global configuration class, @ExceptionHandler handles exceptions uniformly)
随机推荐
STM32问题合集
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
学习DAVID数据库(1)
测试中的误报和漏报同样的值得反复修正
2022 Nioke Multi-School League Game 4 Solution
[C language foundation] Solve C language error: expected ';', ',' or ')' before '&' token
els 方块向左移动条件判断
Detailed explanation of TCP (1)
11. Redis implements follow, unfollow, and follow and follower lists
LeetCode simple problem to find the subsequence of length K with the largest sum
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
【编译原理】词法分析程序设计原理与实现
IDEA 注释报红解决
3.5 】 【 Cocos Creator slow operating system to stop all animations
【CocosCreator 3.5】CocosCreator get network status
How to develop a high-quality test case?
Addition and Subtraction of Scores in LeetCode Medium Questions
大小端模式
遗留系统的自动化策略
【HCIP】ISIS