### Add Flutter Platform Widgets Package Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/get_started.md Use the `flutter pub add` command to quickly add the `flutter_platform_widgets` package to your project's dependencies. ```bash $ flutter pub add flutter_platform_widgets ``` -------------------------------- ### Declare Flutter Platform Widgets Dependency in pubspec.yaml Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/get_started.md Manually add or verify the `flutter_platform_widgets` dependency in your `pubspec.yaml` file, specifying the desired version (e.g., `{LATEST}`). ```yaml dependencies: flutter_platform_widgets: {LATEST} ``` -------------------------------- ### Import Flutter Platform Widgets in Dart Files Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/get_started.md Include the necessary import statement at the top of any Dart file where you intend to use components from the `flutter_platform_widgets` package. ```dart import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; ``` -------------------------------- ### Configure Flutter Platform Widgets with PlatformApp Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/app_setup.md This snippet demonstrates how to wrap your application with `PlatformProvider` and use `PlatformApp` as the root widget. This setup is recommended for closer adherence to iOS (Cupertino) styling and behavior, and allows for further configuration. It includes essential `localizationsDelegates` for proper Cupertino widget functionality. ```dart PlatformProvider( builder: (context) => PlatformApp( localizationsDelegates: >[ DefaultMaterialLocalizations.delegate, DefaultWidgetsLocalizations.delegate, DefaultCupertinoLocalizations.delegate, ], title: 'Flutter Platform Widgets', home: MyHomePage(), ), ) ``` -------------------------------- ### Configure Flutter Platform Widgets with PlatformApp.router for Navigator 2.0 Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/app_setup.md This snippet shows how to use `PlatformApp.router` with `PlatformProvider` when implementing the new Navigator 2.0. Similar to `PlatformApp`, it requires `localizationsDelegates` for Cupertino compatibility and allows for custom `routeInformationParser` and `routerDelegate`. ```dart PlatformProvider( builder: (context) => PlatformApp.router( localizationsDelegates: >[ DefaultMaterialLocalizations.delegate, DefaultWidgetsLocalizations.delegate, DefaultCupertinoLocalizations.delegate, ], title: 'Flutter Platform Widgets', routeInformationParser: ... routerDelegate: ... ), ) ``` -------------------------------- ### Enable Material Widgets within a Cupertino Flutter App Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/app_setup.md This snippet illustrates how to configure `PlatformProvider` to allow the use of Material widgets, such as `ListTile`, within an application primarily styled for Cupertino. Setting `iosUsesMaterialWidgets: true` in `PlatformSettingsData` prevents exceptions when Material widgets lack a Material parent. ```dart PlatformProvider( settings: PlatformSettingsData(iosUsesMaterialWidgets: true), builder: ... ) ``` -------------------------------- ### Registering Service Worker for Flutter Web Applications Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/example/web/index.html This JavaScript snippet checks if the browser supports service workers. If supported, it adds an event listener for `flutter-first-frame` to ensure the Flutter app has initialized before attempting to register the `flutter_service_worker.js` file. This is crucial for enabling offline capabilities and caching for Flutter web apps. ```JavaScript if ('serviceWorker' in navigator) { window.addEventListener('flutter-first-frame', function () { navigator.serviceWorker.register('flutter_service_worker.js'); }); } ``` -------------------------------- ### Apply Material-based Cupertino Theme in PlatformApp (Flutter) Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/theming.md Demonstrates how to configure a `PlatformApp` to use a `CupertinoTheme` derived from the `MaterialTheme` using `MaterialBasedCupertinoThemeData`. This approach ensures consistent theming across Material and Cupertino widgets by linking the Cupertino theme to the Material theme configuration. ```dart final materialTheme = ThemeData( primarySwatch: Colors.green, ); return Theme( data: materialTheme, child: PlatformProvider( builder: (context) => PlatformApp( localizationsDelegates: ..., title: ..., home: ..., material: (_, __) => MaterialAppData( theme: materialTheme, ), cupertino: (_, __) => CupertinoAppData( theme: MaterialBasedCupertinoThemeData(materialTheme: materialTheme), ), ), ), ); ``` -------------------------------- ### Open Xcode Workspace for iOS Asset Management Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md This command opens the Xcode workspace for your Flutter project, which is necessary to access and manage iOS-specific assets like launch screen images within the `Runner/Assets.xcassets` catalog. ```Shell open ios/Runner.xcworkspace ``` -------------------------------- ### Simplified Platform Widget Rendering with Flutter Platform Widgets Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/README.md This snippet illustrates how the `flutter_platform_widgets` library simplifies cross-platform UI development. Instead of conditional logic, a single `PlatformElevatedButton` is used. The library automatically renders the correct underlying Material or Cupertino widget based on the `ThemeData.platform` property, reducing code duplication and effort. ```Dart return PlatformElevatedButton(onPressed: onPressed, child: child); ``` -------------------------------- ### Simplified Platform-Agnostic Button with flutter_platform_widgets Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/index.md This Dart code snippet illustrates how `flutter_platform_widgets` simplifies cross-platform UI development. Instead of conditional checks, it uses `PlatformElevatedButton`, which automatically renders the appropriate Material or Cupertino button based on the detected platform. This reduces boilerplate and improves code readability. ```dart Widget build(BuildContext context) { return PlatformElevatedButton( onPressed: () => onAction(), child: **PlatformText**('Action'), ); } ``` -------------------------------- ### Configure Dynamic Cupertino Theme for Brightness (Flutter) Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/theming.md Explains how to use `CupertinoDynamicColor` within `CupertinoThemeData` to define colors that adapt automatically to light and dark modes. This approach allows Cupertino widgets to dynamically adjust their appearance based on the system's brightness setting. ```dart final cupertinoTheme = CupertinoThemeData( primaryColor: CupertinoDynamicColor.withBrightness( color: Colors.red, darkColor: Colors.blue, ), ); ``` -------------------------------- ### Configure Light and Dark Material Themes in PlatformApp (Flutter) Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/theming.md Shows how to set up separate `ThemeData` instances for light and dark modes in a Material app, then apply them to `MaterialAppData` within `PlatformApp`. This enables automatic theme switching based on the device's brightness setting for Material widgets. ```dart final materialLightTheme = ThemeData( brightness: Brightness.light, primarySwatch: Colors.green, ); final materialDarkTheme = ThemeData( brightness: Brightness.dark, primarySwatch: Colors.cyan, ); return Theme( data: materialTheme, child: PlatformProvider( builder: (context) => PlatformApp( localizationsDelegates: ..., title: ..., home: ..., material: (_, __) => MaterialAppData( theme: materialLightTheme, darkTheme: materialDarkTheme, ), cupertino: ..., ), ), ); ``` -------------------------------- ### Conditional Widget Rendering in Flutter Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/index.md This Dart code snippet demonstrates a common approach in Flutter to render different widgets based on the target platform (iOS/macOS vs. Android). It uses `Theme.of(context).platform` to check the platform and conditionally returns either an `ElevatedButton` (Material) or a `CupertinoButton.filled` (Cupertino). This approach often leads to repetitive conditional logic throughout a codebase. ```dart Widget build(BuildContext context) { final themeData = Theme.of(context); if (themeData.platform == TargetPlatform.iOS || themeData.platform == TargetPlatform.macOS) { return ElevatedButton( onPressed: () => onAction(), child: Text('ACTION'), ); } else { return CupertinoButton.filled( onPressed: () => onAction(), child: Text('Action'), ); } } ``` -------------------------------- ### Apply Direct Cupertino Theme in PlatformApp (Flutter) Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/docs/theming.md Illustrates how to apply a distinct `CupertinoThemeData` directly to a `PlatformApp`'s Cupertino configuration. This method is suitable when the Cupertino design requires a different aesthetic from the Material theme, allowing for independent styling. ```dart final materialTheme = ThemeData( primarySwatch: Colors.green, ); final cupertinoTheme = CupertinoThemeData( primaryColor: Colors.red, ); return Theme( data: materialTheme, child: PlatformProvider( builder: (context) => PlatformApp( localizationsDelegates: ..., title: ..., home: ..., material: (_, __) => MaterialAppData( theme: materialTheme, ), cupertino: (_, __) => CupertinoAppData( theme: cupertinoTheme, ), ), ), ); ``` -------------------------------- ### Conditional Platform Widget Rendering in Dart Source: https://github.com/stryder-dev/flutter_platform_widgets/blob/master/README.md This code snippet demonstrates the traditional approach to rendering platform-specific widgets in Flutter. It uses conditional checks (`Platform.isAndroid`, `Platform.isIOS`) to return different widgets (e.g., `ElevatedButton` for Android, `CupertinoButton.filled` for iOS) based on the detected operating system. This method requires duplicating UI logic for each platform. ```Dart if (Platform.isAndroid) { return ElevatedButton(onPressed: onPressed, child: child); } else if (Platform.isIOS) { return CupertinoButton.filled(onPressed: onPressed, child: child); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.