当前位置:网站首页>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!; }); }, ), ], )); }}运行效果如下图
下一节我们将解 输入框及表单
边栏推荐
- 1175. 质数排列 : 乘法原理运用题
- Object mapping - mapping Mapster
- Customize an annotation to get a link to the database
- R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram, and_ Set the alpha parameter in the point parameter to specify the transparency level of data points (points transparent
- 用于生成学习任务的量子神经网络2022最新综述
- Object mapping - mapping Mapster
- 学习redis实现分布式锁—–自己的一个理解
- 安装onnx很慢,使用清华镜像
- R language ggplot2 visualization: use ggplot2 visualization scatter diagram and the size parameter in AES function to specify the size of data points (point size)
- 据说用了这个,老板连夜把测试开了
猜你喜欢

CVPR 2022 | greatly reduce the manual annotation required for zero sample learning. Mapu and Beiyou proposed category semantic embedding rich in visual information

MySQL 复合查询

STM32F407ZGT6使用SDIO方式驱动SD卡

wallys/3 × 3 MIMO 802.11ac Mini PCIe Wi-Fi Module, QCA9880, 2,4GHz / 5GHzDesigned for Enterprise

盘点那些具有特色的写作软件

Stm32f407zgt6 uses SDIO mode to drive SD card

The first batch in China! Alibaba cloud native data Lake products have passed the evaluation and certification of the ICT Institute

21、wpf之绑定使用小记

Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution

c# 怎样能写个sql的解析器
随机推荐
Pointdistiller: structured knowledge distillation for efficient and compact 3D detection
Multiparty cardinality testing for threshold private set-2021: Interpretation
MySQL 内置函数
Summer vacation study record
Multiparty cardinality testing for threshold private set-2021: Interpretation
"War" caused by a bottle of water
How to 'gracefully' avoid MySQL login prompt information in scripts
R语言ggplot2可视化:使用ggplot2可视化散点图、在geom_point参数中设置show_legend参数为FALSE配置不显示图例信息
他是上海两大产业的第一功臣,却在遗憾中默默离世
R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ The size function configures the measurement adjustment range of the size of the data point
R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_x_log10函数配置X轴的数值范围为对数坐标
自定义一个注解来获取数据库的链接
Analysis of KOA - onion model
AutoCAD - len command
Embedded SIG | 多 OS 混合部署框架
R语言ggplot2可视化:使用ggplot2可视化散点图、使用scale_color_viridis_d函数指定数据点的配色方案
据说用了这个,老板连夜把测试开了
Dameng data rushes to the scientific innovation board, or becomes the "first share of domestic database" in the A-share market
【重温经典C语言】~c语言中%x、%c、%d、%x等等等、c语言取地址符&的作用、C语言中的 联合体
ClipboardJS——开发学习总结1