diff --git a/CHANGELOG.md b/CHANGELOG.md index 98be49d..274e225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Changelog -## 2.1.0 +## 2.1.2 + +- Fix Playx boot initialization inside Sentry's `appRunner` zone. +- Add `appRunner` support to `runPlayx`. +- Deprecate the `app` parameter in `runPlayx`. + +## 2.1.0 - 2.1.1 ### Dependency Updates -* `playx_navigation: ^2.0.0` +* `playx_navigation: ^2.1.0` ### Navigation Enhancements (`playx_navigation` 2.0.0) * **Updated `PlayxNavigationSettings.goRouter`** to accept the new `PlayxPageConfig? config` parameter, enabling global defaults for: diff --git a/example/lib/main.dart b/example/lib/main.dart index cc1351c..d1b9343 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -15,7 +15,7 @@ void main() async { fileName: 'assets/env/keys.env', ), localeConfigBuilder: () => createLocaleConfig(), - app: const MyApp(), + appRunner: () => runApp(const MyApp()), //not necessary // sentryOptions: (options) { // options.dsn = AppConfig.sentryKey; @@ -26,7 +26,12 @@ void main() async { final goRouter = GoRouter( routes: [ PlayxRoute( - path: '/', builder: (context, state, isInitialized) => const Home()), + path: '/', + builder: ( + context, + state, + ) => + const Home()), ], ); diff --git a/example/pubspec.lock b/example/pubspec.lock index f1e4375..d9700e2 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -691,7 +691,7 @@ packages: path: ".." relative: true source: path - version: "2.1.0" + version: "2.1.1" playx_core: dependency: transitive description: @@ -712,10 +712,10 @@ packages: dependency: transitive description: name: playx_navigation - sha256: "31f774a4da59e7264d2647094b35f0640b78f65cfd68fa3f82f19e28bbe22776" + sha256: "199939b6928cd739209543dad86f0c7e7489bc63b3a2b94a98593a9d98afd339" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "2.1.0" playx_network: dependency: transitive description: diff --git a/lib/src/playx.dart b/lib/src/playx.dart index facd7f5..72c5d0d 100644 --- a/lib/src/playx.dart +++ b/lib/src/playx.dart @@ -11,6 +11,7 @@ typedef PlayxAppConfigBuilder = PlayXAppConfig Function(); typedef PlayxLocaleConfigBuilder = PlayxLocaleConfig Function(); typedef PlayxThemeConfigBuilder = PlayxThemeConfig Function(); typedef PlayxEnvSettingsBuilder = PlayxEnvSettings Function()?; +typedef PlayxAppRunner = FutureOr Function(); /// The Playx library provides a suite of utilities for app setup, configuration, and management. /// @@ -147,7 +148,7 @@ abstract class Playx { /// Wraps `runApp` to initialize and set up Playx packages before running the app. /// - /// [app]: The root widget of the application. + /// [appRunner]: Runs the application after Playx finishes booting. /// [appConfigBuilder]: A function that returns the app configuration. /// [localeConfigBuilder]: A function that returns the locale configuration. /// [themeConfigBuilder]: A function that returns the theme configuration. @@ -157,7 +158,7 @@ abstract class Playx { /// [envSettingsBuilder]: A function that returns optional environment settings. /// [sentryOptions]: Optional Sentry configuration for crash reporting. static Future runPlayx({ - required Widget app, + PlayxAppRunner? appRunner, PlayxAppConfigBuilder? appConfigBuilder, PlayxLocaleConfigBuilder? localeConfigBuilder, PlayxThemeConfigBuilder? themeConfigBuilder, @@ -169,6 +170,7 @@ abstract class Playx { FlutterOptionsConfiguration? sentryOptions, PlayxWebSettings webSettings = const PlayxWebSettings(), // Deprecated parameters + @Deprecated('Use appRunner instead.') Widget? app, @Deprecated('Use appConfigBuilder instead.') PlayXAppConfig? appConfig, @Deprecated('Use localeConfigBuilder instead.') PlayxLocaleConfig? localeConfig, @@ -200,31 +202,53 @@ abstract class Playx { (envSettingsBuilder == null && envSettings != null), 'Use either envSettingsBuilder or envSettings, not both.', ); - - // Boots Playx dependencies. - await boot( - appConfig: appConfig, - themeConfig: themeConfig, - envSettings: envSettings, - localeConfig: localeConfig, - appConfigBuilder: appConfigBuilder, - localeConfigBuilder: localeConfigBuilder, - themeConfigBuilder: themeConfigBuilder, - envSettingsBuilder: envSettingsBuilder, - securePrefsSettings: securePrefsSettings, - prefsSettings: prefsSettings, - workManagerSettings: workManagerSettings, - webSettings: webSettings, + assert( + (appRunner != null && app == null) || + (appRunner == null && app != null), + 'Use either appRunner or app, not both.', ); + final resolvedAppRunner = appRunner ?? () => runApp(app!); + if (sentryOptions != null) { await SentryFlutter.init( sentryOptions, - // Run the app after initializing Sentry. - appRunner: () => runApp(app), + // Boot Playx inside Sentry's app runner so binding initialization and + // runApp execute in the same zone, especially on Flutter web. + appRunner: () async { + await boot( + appConfig: appConfig, + themeConfig: themeConfig, + envSettings: envSettings, + localeConfig: localeConfig, + appConfigBuilder: appConfigBuilder, + localeConfigBuilder: localeConfigBuilder, + themeConfigBuilder: themeConfigBuilder, + envSettingsBuilder: envSettingsBuilder, + securePrefsSettings: securePrefsSettings, + prefsSettings: prefsSettings, + workManagerSettings: workManagerSettings, + webSettings: webSettings, + ); + await Future.sync(resolvedAppRunner); + }, ); } else { - runApp(app); + await boot( + appConfig: appConfig, + themeConfig: themeConfig, + envSettings: envSettings, + localeConfig: localeConfig, + appConfigBuilder: appConfigBuilder, + localeConfigBuilder: localeConfigBuilder, + themeConfigBuilder: themeConfigBuilder, + envSettingsBuilder: envSettingsBuilder, + securePrefsSettings: securePrefsSettings, + prefsSettings: prefsSettings, + workManagerSettings: workManagerSettings, + webSettings: webSettings, + ); + await Future.sync(resolvedAppRunner); } } diff --git a/pubspec.yaml b/pubspec.yaml index c9350c7..38a8a9b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: playx description: Playx eco system helps with redundant features as it provides many utilities for themes, widgets and more. -version: 2.1.0 +version: 2.1.2 homepage: https://sourcya.io repository: https://github.com/playx-flutter/playx issue_tracker: https://github.com/playx-flutter/playx/issues @@ -23,7 +23,7 @@ dependencies: playx_theme: ^2.0.0 playx_widget: ^0.5.0 playx_network: ^1.0.0 - playx_navigation: ^2.0.0 + playx_navigation: ^2.1.0 playx_localization: ^0.4.0 queen_validators: ^1.0.1 sentry_flutter: ^9.17.0