SuperAPI AI 工具集

shadcn_ui-switch

前端与建站

查看项目

更新于 10-16 04:00

技能介绍

Shadcn UI — Switch 技能用于在 Flutter 项目中添加开关(Toggle Switch)组件,实现在开与关、选中与未选中之间的状态切换,并支持在表单中作为开关类型的字段使用。

主要能力 提供两个组件:ShadSwitch 用于独立使用的开关控件,ShadSwitchFormField 用于表单场景的开关字段。ShadSwitch 通过 value 与 onChanged 管理状态,可通过 label 传入标签内容。ShadSwitchFormField 额外支持 id、initialValue、inputLabel、inputSublabel 与 validator 参数,可在表单中校验开关状态。

使用方式 独立开关示例:

ShadSwitch( value: value, onChanged: (v) => setState(() => value = v), label: const Text('Airplane Mode'), )

表单字段示例:

ShadSwitchFormField( id: 'terms', initialValue: false, inputLabel: const Text('I accept the terms and conditions'), onChanged: (v) {}, inputSublabel: const Text('You agree to our Terms and Conditions'), validator: (v) { if (!v) return 'You must accept the terms and conditions'; return null; }, )

适用场景 适用于 Flutter 应用中需要开/关切换的界面元素,例如设置项开关;也适用于表单中需要用户确认或勾选的开关字段,并通过 validator 强制校验(如必须接受条款)。

限制 当前资料仅提供组件名称、参数与示例代码,未说明支持的 Flutter 版本、依赖安装步骤、主题定制能力、无障碍支持及其他平台差异等信息,这些内容暂未提供。