diff --git a/example/lib/main.dart b/example/lib/main.dart index 4fba073..7910f42 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,10 +1,12 @@ import 'dart:async'; import 'package:example/src/common/util/error_util.dart'; -import 'package:example/src/common/widget/app.dart'; -import 'package:example/src/common/widget/app_error.dart'; -import 'package:example/src/feature/initialization/data/initialization.dart'; -import 'package:example/src/feature/initialization/widget/inherited_dependencies.dart'; +import 'package:example/src/common/widget/app.dart' deferred as app; +import 'package:example/src/common/widget/app_error.dart' deferred as app_error; +import 'package:example/src/feature/initialization/data/initialization.dart' + deferred as initialization; +import 'package:example/src/feature/initialization/widget/inherited_dependencies.dart' + deferred as inherited_dependencies; import 'package:flutter/widgets.dart'; import 'package:l/l.dart'; @@ -16,20 +18,26 @@ void main() => l.capture( ValueNotifier<({int progress, String message})>( (progress: 0, message: '')); /* runApp(SplashScreen(progress: initializationProgress)); */ - $initializeApp( - onProgress: (progress, message) => initializationProgress.value = - (progress: progress, message: message), - onSuccess: (dependencies) => runApp( - InheritedDependencies( - dependencies: dependencies, - child: const App(), - ), - ), - onError: (error, stackTrace) { - runApp(AppError(error: error)); - ErrorUtil.logError(error, stackTrace).ignore(); - }, - ).ignore(); + await initialization.loadLibrary(); + await inherited_dependencies.loadLibrary(); + await app.loadLibrary(); + initialization + .$initializeApp( + onProgress: (progress, message) => initializationProgress + .value = (progress: progress, message: message), + onSuccess: (dependencies) => runApp( + inherited_dependencies.InheritedDependencies( + dependencies: dependencies, + child: app.App(), + ), + ), + onError: (error, stackTrace) async { + await app_error.loadLibrary(); + runApp(app_error.AppError(error: error)); + ErrorUtil.logError(error, stackTrace).ignore(); + }, + ) + .ignore(); }, l.e, ), diff --git a/example/lib/src/common/router/routes.dart b/example/lib/src/common/router/routes.dart index 4bb037d..212a6d7 100644 --- a/example/lib/src/common/router/routes.dart +++ b/example/lib/src/common/router/routes.dart @@ -6,14 +6,8 @@ import 'package:example/src/feature/authentication/widget/signup_screen.dart'; import 'package:example/src/feature/gallery/widget/gallery_screen.dart'; import 'package:example/src/feature/gallery/widget/picture_screen.dart'; import 'package:example/src/feature/home/widget/home_screen.dart'; -import 'package:example/src/feature/shop/widget/basket_screen.dart'; -import 'package:example/src/feature/shop/widget/catalog_screen.dart'; -import 'package:example/src/feature/shop/widget/category_screen.dart'; -import 'package:example/src/feature/shop/widget/checkout_screen.dart'; -import 'package:example/src/feature/shop/widget/favorites_screen.dart'; -import 'package:example/src/feature/shop/widget/product_image_dialog.dart'; -import 'package:example/src/feature/shop/widget/product_screen.dart'; -import 'package:example/src/feature/shop/widget/shop_screen.dart'; +import 'package:example/src/feature/shop/shop_screens.dart' + deferred as shop_screens; import 'package:flutter/material.dart'; import 'package:octopus/octopus.dart'; @@ -49,17 +43,34 @@ enum Routes with OctopusRoute { Routes.signin => const SignInScreen(), Routes.signup => const SignUpScreen(), Routes.home => const HomeScreen(), - Routes.shop => const ShopScreen(), - Routes.catalog => const CatalogScreen(), - Routes.category => CategoryScreen(id: node.arguments['id']), - Routes.product => ProductScreen(id: node.arguments['id']), - Routes.productImageDialog => ProductImageDialog( - id: node.arguments['id'], - idx: node.arguments['idx'], + Routes.shop => + _ShopLoader(builder: (context) => shop_screens.ShopScreen()), + Routes.catalog => _ShopLoader( + builder: (context) => shop_screens.CatalogScreen(), + ), + Routes.category => _ShopLoader( + builder: (context) => + shop_screens.CategoryScreen(id: node.arguments['id']), + ), + Routes.product => _ShopLoader( + builder: (context) => + shop_screens.ProductScreen(id: node.arguments['id']), + ), + Routes.productImageDialog => _ShopLoader( + builder: (context) => shop_screens.ProductImageDialog( + id: node.arguments['id'], + idx: node.arguments['idx'], + ), + ), + Routes.basket => _ShopLoader( + builder: (context) => shop_screens.BasketScreen(), + ), + Routes.checkout => _ShopLoader( + builder: (context) => shop_screens.CheckoutScreen(), + ), + Routes.favorites => _ShopLoader( + builder: (context) => shop_screens.FavoritesScreen(), ), - Routes.basket => const BasketScreen(), - Routes.checkout => const CheckoutScreen(), - Routes.favorites => const FavoritesScreen(), Routes.gallery => const GalleryScreen(), Routes.picture => PictureScreen(id: node.arguments['id']), Routes.profile => const ProfileScreen(), @@ -75,3 +86,26 @@ enum Routes with OctopusRoute { : super.pageBuilder(context, node); */ } + +class _ShopLoader extends StatelessWidget { + const _ShopLoader({ + required this.builder, + super.key, // ignore: unused_element + }); + + static final Future _loadShop = shop_screens.loadLibrary(); + + final WidgetBuilder builder; + + @override + Widget build(BuildContext context) => FutureBuilder( + initialData: null, + future: _loadShop, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return builder(context); + } + return const Center(child: CircularProgressIndicator()); + }, + ); +} diff --git a/example/lib/src/feature/shop/shop_screens.dart b/example/lib/src/feature/shop/shop_screens.dart new file mode 100644 index 0000000..fa26e4a --- /dev/null +++ b/example/lib/src/feature/shop/shop_screens.dart @@ -0,0 +1,8 @@ +export 'package:example/src/feature/shop/widget/basket_screen.dart'; +export 'package:example/src/feature/shop/widget/catalog_screen.dart'; +export 'package:example/src/feature/shop/widget/category_screen.dart'; +export 'package:example/src/feature/shop/widget/checkout_screen.dart'; +export 'package:example/src/feature/shop/widget/favorites_screen.dart'; +export 'package:example/src/feature/shop/widget/product_image_dialog.dart'; +export 'package:example/src/feature/shop/widget/product_screen.dart'; +export 'package:example/src/feature/shop/widget/shop_screen.dart'; diff --git a/example/pubspec.lock b/example/pubspec.lock index 4520038..88e630c 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -498,7 +498,7 @@ packages: path: ".." relative: true source: path - version: "0.0.6" + version: "0.0.8" package_config: dependency: transitive description: