当前位置:网站首页>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!; }); }, ), ], )); }}运行效果如下图
下一节我们将解 输入框及表单
边栏推荐
- Le talent scientifique 丨 dessins animés qu'est - ce qu'erdma?
- Speech recognition - Fundamentals (I): introduction [speech to text]
- Multiparty Cardinality Testing for Threshold Private Set-2021:解读
- 服务器常用的一些硬件信息(不断更新)
- Object mapping - mapping Mapster
- R语言ggplot2可视化:使用ggplot2可视化散点图、aes函数中的colour参数指定不同分组的数据点使用不同的颜色显示
- 科普達人丨漫畫圖解什麼是eRDMA?
- R语言ggplot2可视化分面图(facet):gganimate包基于transition_time函数创建动态散点图动画(gif)、使用labs函数为动画图添加动态时间标题
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_size函数配置数据点的大小的(size)度量调整的范围
- 建立自己的网站(13)
猜你喜欢

STM32F407ZGT6使用SDIO方式驱动SD卡

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

led背光板的作用是什麼呢?

1175. prime permutation

MySQL 表的内连和外连

EMC surge

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

线下门店为什么要做新零售?
![Speech recognition - Fundamentals (I): introduction [speech to text]](/img/28/eb45bf27fffaa29108de84aa72a335.png)
Speech recognition - Fundamentals (I): introduction [speech to text]

Oracle netsuite helps TCM bio understand data changes and make business development more flexible
随机推荐
Is the golden cycle of domestic databases coming?
R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_color_viridis_d函数指定数据点的配色方案
Review the writing software with characteristics
对象映射 - Mapping.Mapster
Typescript readonlyarray (read only array type) details
安装onnx很慢,使用清华镜像
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and_ Set show in the point parameter_ The legend parameter is false, and the legend information is not displayed
会议预告 | 华为 2012 实验室全球软件技术峰会-欧洲分会场
Go zero micro Service Practice Series (VIII. How to handle tens of thousands of order requests per second)
How can c write an SQL parser
R语言ggplot2可视化:使用ggplot2可视化散点图、在geom_point参数中设置show_legend参数为FALSE配置不显示图例信息
构造函数、类成员、析构函数调用顺序
智慧法院新征程,无纸化办公,护航智慧法院绿色庭审
If it is not listed again, Kuangshi technology will not be able to endure
据说用了这个,老板连夜把测试开了
Boost研究:Boost Log
Learn how to implement distributed locks in redis - my own understanding
A quietly rising domestic software, low-key and powerful!
After the node is installed in the NVM, the display is not internal or external when the NPM instruction is used
R language ggplot2 visual Facet: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF) and uses the labs function to add a dynamic time title to t