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();
    }
}
copied to clipboard

You also can use UITargetPlatform.of,

  final platform = UITargetPlatform.of(context);
copied to clipboard

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

1
likes
150
points
32
downloads

Publisher

unverified uploader

Weekly Downloads

2024.10.03 - 2025.04.17

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

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on ui_target_platform