当前位置:网站首页>Flutter 从零开始 006 单选开关和复选框
Flutter 从零开始 006 单选开关和复选框
2022-06-30 11:42:00 【华为云】
在平时的项目编写工作中,我们用到单选开关和复选框的次数还是比较多的,我们今天简单的介绍一下单选开关和复选框的原理,后期我们再详细的介绍一下单选开关和复选框的自定义和封装使用。
Material 组件库中提供了 Material 风格的单选开关Switch和复选框Checkbox,虽然它们都是继承自StatefulWidget,但它们本身不会保存当前选中状态,选中状态都是由父组件来管理的。当Switch或Checkbox被点击时,会触发它们的onChanged回调,我们可以在此回调中处理选中状态改变逻辑。下面有一个简单的例子
class _MyHomePageState extends State<MyHomePage> { bool _swithSelected = true; // 单选开关的状态,我们默认选中 bool _checkBoxSelected = true; // 复选框的状态,我们默认选中 @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Switch( value: _swithSelected, // 当前状态 onChanged: (value) { //状态监听, 重新构建状态 setState(() { _swithSelected = value; }); }, ), Checkbox( value: _checkBoxSelected, activeColor: Colors.blue, //选中时的颜色 onChanged: (value) { setState(() { _checkBoxSelected = value!; }); }, ), ], )); }}运行效果如下图
下一节我们将解 输入框及表单
边栏推荐
- Evaluation of IP location query interface Ⅲ
- 使用深度学习进行生物网络分析
- led背光板的作用是什麼呢?
- Review the writing software with characteristics
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_x_log10函数配置X轴的数值范围为对数坐标
- 网络营销之四大误解
- 线下门店为什么要做新零售?
- HMS core audio editing service 3D audio technology helps create an immersive auditory feast
- Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
- 60 个神级 VS Code 插件!!
猜你喜欢

Evaluation of IP location query interface Ⅲ

服务器常用的一些硬件信息(不断更新)

Who still remembers "classmate Zhang"?
Redis - ziplist compressed list

Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?

【模式识别大作业】

R language view version R package view version

据说用了这个,老板连夜把测试开了

Alibaba cloud database represented by polardb ranks first in the world

The operation and maintenance security gateway (Fortress machine) of Qiming star group once again won the first place!
随机推荐
Lucene全文检索工具包学习笔记总结
ClipboardJS——开发学习总结1
time 函数和 clock_gettime()函数的区别
EMC surge
Embedded SIG | 多 OS 混合部署框架
Limited time appointment | Apache pulsar Chinese developer and user group meeting in June
Stm32f407zgt6 uses SDIO mode to drive SD card
使用深度学习进行生物网络分析
Oracle netsuite helps TCM bio understand data changes and make business development more flexible
wallys/600VX – 2×2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz QCA 9880
Dameng data rushes to the scientific innovation board, or becomes the "first share of domestic database" in the A-share market
Review the writing software with characteristics
构造函数、类成员、析构函数调用顺序
R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的colour参数指定不同分组的数据点使用不同的颜色显示
重新理解oauth2.0协议进行联合登录
他是上海两大产业的第一功臣,却在遗憾中默默离世
1175. 质数排列 : 乘法原理运用题
R language ggplot2 visualization: use ggplot2 visualization scatter diagram and the color parameter in AES function to specify that data points in different groups are displayed in different colors
21、wpf之绑定使用小记
Uncover the whole link communication process of customer service im