diff --git a/packages/flutter_product_page/lib/src/configuration/product_page_configuration.dart b/packages/flutter_product_page/lib/src/configuration/product_page_configuration.dart index f80d30a..616bea4 100644 --- a/packages/flutter_product_page/lib/src/configuration/product_page_configuration.dart +++ b/packages/flutter_product_page/lib/src/configuration/product_page_configuration.dart @@ -26,6 +26,9 @@ class ProductPageConfiguration { this.discountDescription, this.noContentBuilder, this.errorBuilder, + this.shopselectorBuilder, + this.discountBuilder, + this.categoryListBuilder, }) { onProductDetail ??= _onProductDetail; discountDescription ??= _defaultDiscountDescription; @@ -45,13 +48,13 @@ class ProductPageConfiguration { final Future> Function(Shop shop) getProducts; /// The localizations for the product page. - ProductPageTranslations translations; + final ProductPageTranslations translations; /// Builder for the product item. These items will be displayed in the list /// for each product in their seperated category. This builder should only /// build the widget for one specific product. This builder has a default /// in-case the developer does not override it. - Widget Function( + final Widget Function( BuildContext context, Product product, ProductPageConfiguration configuration, @@ -66,7 +69,7 @@ class ProductPageConfiguration { /// The builder for the shopping cart. This builder should return a widget /// that navigates to the shopping cart overview page. - Widget Function( + final Widget Function( BuildContext context, ProductPageConfiguration configuration, )? shoppingCartButtonBuilder; @@ -93,29 +96,53 @@ class ProductPageConfiguration { final Function() onNavigateToShoppingCart; /// The style of the shop selector. - ShopSelectorStyle shopSelectorStyle; + final ShopSelectorStyle shopSelectorStyle; /// The padding for the page. - EdgeInsets pagePadding; + final EdgeInsets pagePadding; /// Optional app bar that you can pass to the product page screen. final Widget? bottomNavigationBar; /// Optional app bar that you can pass to the order detail screen. - PreferredSizeWidget Function(BuildContext context)? appBarBuilder; + final PreferredSizeWidget Function(BuildContext context)? appBarBuilder; /// Builder for the no content widget. This builder is used when there is no /// content to display. - Widget Function( + final Widget Function( BuildContext context, )? noContentBuilder; /// Builder for the error widget. This builder is used when there is an error /// to display. - Widget Function( + final Widget Function( BuildContext context, Object? error, )? errorBuilder; + + /// Builder for the shop selector. This builder is used to build the shop + /// selector that will be displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List shops, + Function(Shop shop) onShopSelectionChange, + )? shopselectorBuilder; + + /// Builder for the discount widget. This builder is used to build the + /// discount widget that will be displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List discountedProducts, + )? discountBuilder; + + /// Builder for the list of items that are displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List products, + )? categoryListBuilder; } Future _onProductDetail( diff --git a/packages/flutter_product_page/lib/src/configuration/product_page_translations.dart b/packages/flutter_product_page/lib/src/configuration/product_page_translations.dart index 0129a53..ff6bfd2 100644 --- a/packages/flutter_product_page/lib/src/configuration/product_page_translations.dart +++ b/packages/flutter_product_page/lib/src/configuration/product_page_translations.dart @@ -6,6 +6,8 @@ class ProductPageTranslations { this.discountTitle = "Weekly offer", this.failedToLoadImageExplenation = "Failed to load image", this.close = "Close", + this.categoryItemListTitle = "What would you like to order", + this.appBarTitle = "ProductPage", }); /// Message to navigate to the shopping cart @@ -19,4 +21,10 @@ class ProductPageTranslations { /// Close button for the product page final String close; + + /// Title for the category item list + final String categoryItemListTitle; + + /// Title for the app bar + final String appBarTitle; } diff --git a/packages/flutter_product_page/lib/src/product_page_screen.dart b/packages/flutter_product_page/lib/src/product_page_screen.dart index 85fc777..9489d7a 100644 --- a/packages/flutter_product_page/lib/src/product_page_screen.dart +++ b/packages/flutter_product_page/lib/src/product_page_screen.dart @@ -27,8 +27,10 @@ class ProductPageScreen extends StatelessWidget { @override Widget build(BuildContext context) => Scaffold( - appBar: - configuration.appBarBuilder?.call(context) ?? const DefaultAppbar(), + appBar: configuration.appBarBuilder?.call(context) ?? + DefaultAppbar( + configuration: configuration, + ), bottomNavigationBar: configuration.bottomNavigationBar, body: SafeArea( child: Padding( @@ -129,11 +131,17 @@ class _ProductPage extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - ShopSelector( - configuration: configuration, - shops: shops, - onTap: configuration.shoppingService.shopService.selectShop, - ), + configuration.shopselectorBuilder?.call( + context, + configuration, + shops, + configuration.shoppingService.shopService.selectShop, + ) ?? + ShopSelector( + configuration: configuration, + shops: shops, + onTap: configuration.shoppingService.shopService.selectShop, + ), _ShopContents( configuration: configuration, ), @@ -207,6 +215,7 @@ class _ShopContents extends StatelessWidget { child: Column( children: [ // Products + getCategoryList( context, configuration, @@ -227,25 +236,35 @@ class _ShopContents extends StatelessWidget { children: [ // Discounted product if (discountedproducts.isNotEmpty) ...[ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16), - child: WeeklyDiscount( - configuration: configuration, - product: discountedproducts.first, - ), - ), + configuration.discountBuilder?.call( + context, + configuration, + discountedproducts, + ) ?? + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: WeeklyDiscount( + configuration: configuration, + product: discountedproducts.first, + ), + ), ], Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24), child: Text( - "What would you like to order?", + configuration.translations.categoryItemListTitle, style: theme.textTheme.titleLarge, textAlign: TextAlign.start, ), ), - productList, + configuration.categoryListBuilder?.call( + context, + configuration, + productPageContent, + ) ?? + productList, ], ); }, diff --git a/packages/flutter_product_page/lib/src/widgets/defaults/default_appbar.dart b/packages/flutter_product_page/lib/src/widgets/defaults/default_appbar.dart index 11f2023..9a1cf2b 100644 --- a/packages/flutter_product_page/lib/src/widgets/defaults/default_appbar.dart +++ b/packages/flutter_product_page/lib/src/widgets/defaults/default_appbar.dart @@ -1,12 +1,17 @@ import "package:flutter/material.dart"; +import "package:flutter_product_page/flutter_product_page.dart"; /// Default appbar for the product page. class DefaultAppbar extends StatelessWidget implements PreferredSizeWidget { /// Constructor for the default appbar for the product page. const DefaultAppbar({ + required this.configuration, super.key, }); + /// Configuration for the product page. + final ProductPageConfiguration configuration; + @override Widget build(BuildContext context) { var theme = Theme.of(context); @@ -17,7 +22,7 @@ class DefaultAppbar extends StatelessWidget implements PreferredSizeWidget { IconButton(onPressed: () {}, icon: const Icon(Icons.filter_alt)), ], title: Text( - "Product page", + configuration.translations.appBarTitle, style: theme.textTheme.headlineLarge, ), ); diff --git a/packages/flutter_shopping/lib/src/configuration/shopping_configuration.dart b/packages/flutter_shopping/lib/src/configuration/shopping_configuration.dart index 32583de..c4b0b05 100644 --- a/packages/flutter_shopping/lib/src/configuration/shopping_configuration.dart +++ b/packages/flutter_shopping/lib/src/configuration/shopping_configuration.dart @@ -26,6 +26,9 @@ class ShoppingConfiguration { this.discountDescription, this.noContentBuilder, this.errorBuilder, + this.categoryListBuilder, + this.shopselectorBuilder, + this.discountBuilder, /// ShoppingCart configurations this.onConfirmOrder, @@ -114,6 +117,30 @@ class ShoppingConfiguration { /// Function that will be called when there is an error final Widget Function(BuildContext, Object?)? errorBuilder; + /// Builder for the shop selector. This builder is used to build the shop + /// selector that will be displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List shops, + Function(Shop shop) onShopSelectionChange, + )? shopselectorBuilder; + + /// Builder for the discount widget. This builder is used to build the + /// discount widget that will be displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List discountedProducts, + )? discountBuilder; + + /// Builder for the list of items that are displayed in the product page. + final Widget Function( + BuildContext context, + ProductPageConfiguration configuration, + List products, + )? categoryListBuilder; + /// Function that will be called when the order button on /// the shopping cart page is pressed final Function(List)? onConfirmOrder; @@ -162,12 +189,6 @@ class ShoppingConfiguration { /// Shopping cart app bar builder final AppBar Function(BuildContext)? shoppingCartAppBarBuilder; - // = _defaultPages, -// = const OrderDetailTranslations(), -// = _defaultAppBar, -// = _defaultNextButtonBuilder, -// = _defaultOrderSuccess, - /// Function that gets called when the user navigates to the next /// step of the order details final dynamic Function( diff --git a/packages/flutter_shopping/lib/src/flutter_shopping_navigator_userstory.dart b/packages/flutter_shopping/lib/src/flutter_shopping_navigator_userstory.dart index 4cb5675..e16c05a 100644 --- a/packages/flutter_shopping/lib/src/flutter_shopping_navigator_userstory.dart +++ b/packages/flutter_shopping/lib/src/flutter_shopping_navigator_userstory.dart @@ -52,6 +52,9 @@ class ShoppingProductPage extends StatelessWidget { discountDescription: shoppingConfiguration.discountDescription, noContentBuilder: shoppingConfiguration.noContentBuilder, errorBuilder: shoppingConfiguration.errorBuilder, + shopselectorBuilder: shoppingConfiguration.shopselectorBuilder, + discountBuilder: shoppingConfiguration.discountBuilder, + categoryListBuilder: shoppingConfiguration.categoryListBuilder, shops: () async { if (shoppingConfiguration.onGetShops != null) { return shoppingConfiguration.onGetShops!(); diff --git a/packages/flutter_shopping/pubspec.yaml b/packages/flutter_shopping/pubspec.yaml index d3f1bee..309d6c7 100644 --- a/packages/flutter_shopping/pubspec.yaml +++ b/packages/flutter_shopping/pubspec.yaml @@ -35,13 +35,6 @@ dependencies: url: https://github.com/Iconica-Development/flutter_shopping ref: 2.0.0 path: packages/flutter_shopping_local -dependency_overrides: - flutter_product_page: - path: ../flutter_product_page - flutter_shopping_cart: - path: ../flutter_shopping_cart - flutter_order_details: - path: ../flutter_order_details dev_dependencies: flutter_test: