Skip to content

Instantly share code, notes, and snippets.

@hakburi
Created August 8, 2021 15:24
Show Gist options
  • Save hakburi/588de585168969b1da2e0c52dd6654c3 to your computer and use it in GitHub Desktop.
Save hakburi/588de585168969b1da2e0c52dd6654c3 to your computer and use it in GitHub Desktop.
class PlatformSwitch extends StatefulWidget {
PlatformSwitch();
@override
_PlatformSwitchState createState() => _PlatformSwitchState();
}
class _PlatformSwitchState extends State<PlatformSwitch> {
bool _value = false;
@override
Widget build(BuildContext context) {
if (Platform.isIOS) {
return CupertinoSwitch(value: _value, onChanged: onChanged);
}
return Switch(value: _value, onChanged: onChanged);
}
onChanged(bool value) {
setState(() {
_value = value;
});
}
}
@hakburi
Copy link
Author

hakburi commented Aug 8, 2021

매번 분기처리 하는것이 맘에 들지 않는다면!!

https://pub.dev/packages/flutter_platform_widgets 를 사용하자!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment