Created
August 8, 2021 15:24
-
-
Save hakburi/588de585168969b1da2e0c52dd6654c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
매번 분기처리 하는것이 맘에 들지 않는다면!!
https://pub.dev/packages/flutter_platform_widgets 를 사용하자!