【Flutter】八、Flutter之表单开关——Switch、SwitchListTile

Flutter中开关控件有:Switch、SwitchListTile。Switch仅仅可以定义一个开关,SwitchListTile是一个有标题的开关。

一、Switch

1.1 Switch构造器

const Switch({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.activeColor,
    this.activeTrackColor,
    this.inactiveThumbColor,
    this.inactiveTrackColor,
    this.activeThumbImage,
    this.inactiveThumbImage,
    this.materialTapTargetSize,
    this.dragStartBehavior = DragStartBehavior.start,
  }) : _switchType = _SwitchType.material,
       assert(dragStartBehavior != null),
       super(key: key);

1.2 Switch属性说明

属性说明
bool value开关的值
ValueChanged onChanged开关状态改变回调
Color activeColor激活状态的滑块颜色
Color activeTrackColor激活状态的轨道颜色
Color inactiveThumbColor关闭状态的滑块颜色
Color inactiveTrackColor关闭状态的轨道颜色
ImageProvider activeThumbImage激活状态滑块显示的图片
ImageProvider inactiveThumbImage关闭状态滑块显示的图片
MaterialTapTargetSize materialTapTargetSize该值与CheckBox与Radio中的作用一致
DragStartBehavior dragStartBehavior设置确定当用户启动拖动时,拖动何时正式启动

1.3 Switch示例

在这里插入图片描述

二、SwitchListTile

2.1 SwitchListTile构造器

const SwitchListTile({
    Key key,
    @required this.value,
    @required this.onChanged,
    this.activeColor,
    this.activeTrackColor,
    this.inactiveThumbColor,
    this.inactiveTrackColor,
    this.activeThumbImage,
    this.inactiveThumbImage,
    this.title,
    this.subtitle,
    this.isThreeLine = false,
    this.dense,
    this.secondary,
    this.selected = false,
  }) : _switchListTileType = _SwitchListTileType.material,
       assert(value != null),
       assert(isThreeLine != null),
       assert(!isThreeLine || subtitle != null),
       assert(selected != null),
       super(key: key);

2.2 SwitchListTile属性说明

属性说明
Widget title开关标题
Widget subtitle开关副标题
Widget secondary一个小部件,显示在与开关相对的另一侧
bool isThreeLine是否显示三行
bool dense垂直密集排列
bool selected是否将activeColor应用于title、subtitle、secondary

2.3 SwitchListTile示例

bool _switchListTitleValue = false;

Row(
	children: <Widget>[
		Flexible(
			child: SwitchListTile(
				value: _switchListTitleValue,
				title: Text('SwitchListTile'),
				subtitle: Text('subtitle'),
				secondary: Icon(Icons.close),
				isThreeLine: false,
				dense: false,
				selected: true,
				activeColor: Colors.deepPurpleAccent,
				onChanged: (data){
					setState(() {
						this._switchListTitleValue = data;
					});
				},
			),
		)
	],
)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MAXLZ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值