platform_aware_widgets_flutter icon indicating copy to clipboard operation
platform_aware_widgets_flutter copied to clipboard

Example project showing how to create platform-aware widget classes in Flutter.

Flutter Platform Aware Widgets

Example project showing how to create platform-aware widget classes in Flutter.

Rationale

Flutter has a rich set of Material and Cupertino widgets that can be used to build beautiful looking UIs on Android and iOS.

However, tailoring apps to adopt platform specific conventions can result in a lot of conditionals:

if (Platform.isIOS) {
  // return Cupertino widget
} else {
  // return Material widget
}

This project shows how to abstract away this logic by defining a base PlatformWidget class, that can be subclassed as needed.

This demo shows this approach in practice with a small set of platform-aware widgets.

Supported widgets

  • PlatformSwitch
  • PlatformAlertDialog and PlatformAlertDialogAction
  • PlatformButton
  • PlatformScaffold and PlatformAppBar

Credits

For more articles and video tutorials, check out Coding With Flutter.

License: MIT