class _DemoPageState extends State<DemoPage> { bool check = false; @override Widget build(BuildContext context) { return SwitchListTile( title: Text('是否开启'), secondary: Icon(Icons.print), subtitle: Text('打印照片'), value: check, //激活的圆点颜色 activeColor: Colors.orange, //激活时轨道颜色(不定义,则轨道颜色就是浅一点的圆点颜色 activeTrackColor: Colors.pink, //激活时原点背景图 // activeThumbImage: NetworkImage('url'), //非激活圆点颜色 inactiveThumbColor: Colors.green, //非激活时滑轨颜色 inactiveTrackColor: Colors.blueGrey, //非激活时原点背景图 // inactiveThumbImage: NetworkImage('url'), onChanged: (bool val) { setState(() { check = val; }); }, ); } }
Flutter笔记56:SwitchListTile组件
SwitchListTile是Switch开关组件的增强版,带了标题等功能,基础实行和Switch一样: