介绍Switch按钮的用法。
bool isActive = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('title'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('You have pushed this button many times'),
Text('test2'),
Switch(
value: isActive,
activeColor: Colors.red,
activeTrackColor: Colors.orange,
inactiveThumbColor: Colors.red,
inactiveTrackColor: Colors.blue,
onChanged: (bool value){
isActive = value;
setState((){});
})
],
),
),
);
}