当前位置:网站首页>浅识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, //浮标的位置
);
}
}
边栏推荐
- Ambiguous method call.both
- How to build a private yum source
- The use of font compression artifact font-spider
- 【Cocos Creator 3.5】缓动系统停止所有动画
- 测试中的误报和漏报同样的值得反复修正
- 一份高质量的测试用例如何养成?
- Select the smoke test case, and make the first pass for the product package entering QA
- 递归查询单表-单表树结构-(自用)
- TCP/IP four-layer model
- Difference between unallocated blocks and unused blocks in database files
猜你喜欢

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

【C语言】预处理操作

接口测试关键技术

What is a distributed lock?Three ways of implementing distributed lock

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

分布式系统架构需要解决的问题

Compile Hudi

MP使用时的几个常见报错

CorelDRAW2022 streamlined Asia Pacific new features in detail

With 7 years of experience, how can functional test engineers improve their abilities step by step?
随机推荐
原子操作 CAS
2022牛客多校联赛第四场 题解
编译Hudi
MultipartFile file upload
STM32 problem collection
some of my own thoughts
4. Sensitive word filtering (prefix tree)
CefSharp入门-winform
YOLOV5 study notes (2) - environment installation + operation + training
3.5 】 【 Cocos Creator slow operating system to stop all animations
[Godot][GDScript] 二维洞穴地图随机生成
execsnoop tool
TCP详解(二)
一份高质量的测试用例如何养成?
els block to the right
Local area network computer hardware information collection tool
[Godot][GDScript] 2D cave map randomly generated
Redis实现分布式锁
return in try-catch
TCP/IP four-layer model