Flutter ui_target_platform package

0 0

UITargetPlatform

On Flutter 3.0.5 TargetPlatform enum doesn’t have a value for web platform.

Theme.of(context).platform is used for adapting UI to different platforms, but for web platform you can’t use it (on TargetPlatform enum doesn’t exist web) and must use the kIsWeb global variable.

This package contains the enum UITargetPlatform, that has the same values than TargetPlatform with a new value web.

It also contains the global variable debugDefaultUITargetPlatformIsWeb for testing. The package test_screen uses it for doing web tests.

Usage

Get TargetPlatform from Theme and pass it to UITargetPlatform.fromTargetPlatform().

 @override
  Widget build(BuildContext context) {
    final platform =
        UITargetPlatform.fromTargetPlatform(Theme.of(context).platform);
    switch (platform) {
      case UITargetPlatform.iOS:
        return _cupertinoSlider();
      case UITargetPlatform.web:
        return _webSlider();
      default:
        return _defaultSlider();
    }
}

GitHub

View Github

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Deja una respuesta

Entrada anterior NITC study planner – An android application that helps the students and faculties to maintain their schedule
Entrada siguiente A static Fashion Clone App with Flutter