如果目标平台是iOS,则创建CupertinoSwitch,否则创建material design switch.
Switch.adaptive(value: true, onChanged: (newValue) {})
Sample code:
bool _value = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Switch.adaptive(
value: _value,
onChanged: (newValue) => setState(() => _value = newValue),
),
);
}