How to avoid code duplication when we want Platform specific Widget for Android and Cupertino Widget for iOS like Switch ?
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: (Platform.isAndroid)
? Switch(
value: activate,
onChanged: (value) {
setState(() {
activate = value;
});
},
)
: CupertinoSwitch(
value: activate,
onChanged: (value) {
setState(() {
activate = value;
});
},
)
);
}