Flutter开发 Switch、SwitchListTile的基本使用
Switch
用于开启和关闭的按钮。
属性 | 说明 |
---|---|
value | 开关当前状态 |
activeColor | 开启的颜色 |
activeTrackColor | 开关打开时轨道的颜色 |
inactiveTrackColor | 开关关闭时轨道的颜色 |
activeThumbImage | 开关打开时按钮图片 |
运行效果
class MyState extends State {bool flag = false;Widget build(BuildContext context) {Switch sw = Switch(value: flag,onChanged: (value) {setState(() {flag = value;});},activeColor: Colors.blue,activeTrackColor:Colors.green ,activeThumbImage: NetworkImage("https://pic.rmb.bdstatic.com/bjh/news/49fa0be5e4ab397fe5a04412d5cfe3f6.png"),);return Scaffold(appBar: AppBar(title: Text("Flex"), centerTitle: true),body: sw,);}
}
SwitchListTile
class MyState extends State {bool flag = false; Widget build(BuildContext context) {Column column = Column(children: [SwitchListTile(value: false,onChanged: (value) {},title: Text("6:00"),subtitle: Text("周一至周五响铃"),),SwitchListTile(value: false,onChanged: (value) {},title: Text("10:00"),subtitle: Text("星期六、日响铃"),),],);return Scaffold(appBar: AppBar(title: Text("SwitchListTile"), centerTitle: true),body: column,);}
}