当前位置:网站首页>A brief introduction to the CheckBox component of the basic components of Flutter
A brief introduction to the CheckBox component of the basic components of Flutter
2022-07-31 03:18:00 【A soybean】
浅识Flutter 基本组件之CheckBox组件
常用属性如下表所示
属性名 | 类型 | 功能说明 |
---|---|---|
value | bool | 设置复选框是否选中,取值包括true(选中) 、 false (没选中) |
onChanged | Set up to monitor the value of the checkbox changes back | |
tristate | bool | Set the check box if three states,取值包括true、false和 null |
activeColor | Color | Set the check box selected color |
checkColor | Color | Set the check box selected selected icon()的颜色 |
materialTapTargetSize | double | The size of the set click target,Values implied including padded、shrink Wrap两种 |
Checkbox(value: flag,onChanged: (value){
//setState更新值
setState(() {
flag=value!;
});
},) ,
选中后
Implement the horizontally multiple options
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!;
});
},
),
],
),
选择选项后,Will choose print
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, //浮标的位置
);
}
}
边栏推荐
- SIP Protocol Standard and Implementation Mechanism
- 品牌广告投放平台的中台化应用与实践
- 【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
- What is distributed and clustered?What is the difference?
- 刚出道“一战成名”,安全、舒适一个不落
- Use of QML
- els block to the left to move the conditional judgment
- The Map Entry understanding and application
- CloudCompare & PCL calculate the degree of overlap between two point clouds
- 4. Sensitive word filtering (prefix tree)
猜你喜欢
分布式系统架构需要解决的问题
Graphical lower_bound & upper_bound
Chapter 9 SVM Practice
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
一份高质量的测试用例如何养成?
5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
Detailed explanation of TCP (3)
endian mode
[Compilation principle] Design principle and implementation of recursive descent parsing
Moxa NPort 设备缺陷可能使关键基础设施遭受破坏性攻击
随机推荐
品牌广告投放平台的中台化应用与实践
【异常】The field file exceeds its maximum permitted size of 1048576 bytes.
数据库实现分布式锁
[Compilation principle] Design principle and implementation of recursive descent parsing
分布式锁以及实现方式三种
数据库文件中的未分配的块和未使用的块的区别
YOLOV5 study notes (2) - environment installation + operation + training
Mysql 45讲学习笔记(二十五)MYSQL保证高可用
C primer plus study notes - 8, structure
What skills do I need to learn to move from manual testing to automated testing?
False positives and false negatives in testing are equally worthy of repeated corrections
【编译原理】词法分析程序设计原理与实现
Office automation case: how to automatically generate period data?
Redis实现分布式锁
【AUTOSAR-RTE】-5-Explicit(显式)和Implicit(隐式) Sender-Receiver communication
分布式系统架构需要解决的问题
[Compilation principle] Lexical analysis program design principle and implementation
点云DBSCAN聚类(MATLAB,非内置函数)
Mycat's master-slave relationship, vertical sub-database, horizontal sub-table, and detailed configuration of mycat fragmented table query (mysql5.7 series)
SIP协议标准和实现机制