Switch button
class _MyHomePageState extends State<MyHomePage> { bool flag = true; void change(bool value) { setState(() { flag = value; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Switch( value: Flag,// Set the value, true on, false off onChanged: change,// Call activeColor: Colors. Red,// Set the color circle color for true activeTrackColor: Color. green, // when true, the bar color is activeColor color ActiveThumbColor if this value is not set: Color.blue, // Circle color inactiveTrackColor when false: Yellow,// the color of the bar when false. If this value is not set, the default color is grey // activeThumbImage,// circle image when true // inactiveThumbImage: , / / to false circle picture / / dragStartBehavior: dragStartBehavior. Start, / /), found no effect,),),); }}Copy the code