ui_target_platform 1.1.0 copy "ui_target_platform: ^1.1.0" to clipboard
ui_target_platform: ^1.1.0 copied to clipboard

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

UITargetPlatform #

Pub version

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().

Use UITargetPlatform like TargetPlatform.

 @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();
    }
}

You also can use UITargetPlatform.of,

  final platform = UITargetPlatform.of(context);

that is the same than UITargetPlatform.fromTargetPlatform(Theme.of(context).platform).

1
likes
130
pub points
23%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on ui_target_platform