当前位置:网站首页>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, //浮标的位置
);
}
}
边栏推荐
- 2022 Nioke Multi-School League Game 4 Solution
- 【HCIP】ISIS
- The els block moves the boundary to the right, and accelerates downward.
- endian mode
- C#远程调试
- Select the smoke test case, and make the first pass for the product package entering QA
- Chapter 9 SVM实践
- MultipartFile file upload
- 【C语言】表达式求值的一般方法
- 3.5 】 【 Cocos Creator slow operating system to stop all animations
猜你喜欢
随机推荐
Mysql 45讲学习笔记(二十四)MYSQL主从一致
Use of QML
LeetCode每日一练 —— OR36 链表的回文结构
【Cocos Creator 3.5】缓动系统停止所有动画
[Dynamic programming] Maximum sum of consecutive subarrays
Chapter 9 SVM实践
Good place to download jar packages
原子操作 CAS
观察者模式
浅识Flutter 基本组件之showDatePicker方法
WebSocket Session为null
什么是系统?
【编译原理】词法分析程序设计原理与实现
Analysis summary - self-use
【CocosCreator 3.5】CocosCreator get network status
Distributed locks and three implementation methods
Several common errors when using MP
C# remote debugging
Automation strategies for legacy systems
Map.Entry理解和应用