mirror of
https://github.com/Iconica-Development/flutter_shopping.git
synced 2025-05-19 08:53:46 +02:00
feat: add builders for productpage
This commit is contained in:
parent
f28828b07e
commit
b736072497
7 changed files with 114 additions and 38 deletions
|
@ -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<List<Product>> 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<Shop> 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<Product> discountedProducts,
|
||||
)? discountBuilder;
|
||||
|
||||
/// Builder for the list of items that are displayed in the product page.
|
||||
final Widget Function(
|
||||
BuildContext context,
|
||||
ProductPageConfiguration configuration,
|
||||
List<Product> products,
|
||||
)? categoryListBuilder;
|
||||
}
|
||||
|
||||
Future<void> _onProductDetail(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,6 +131,12 @@ class _ProductPage extends StatelessWidget {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
configuration.shopselectorBuilder?.call(
|
||||
context,
|
||||
configuration,
|
||||
shops,
|
||||
configuration.shoppingService.shopService.selectShop,
|
||||
) ??
|
||||
ShopSelector(
|
||||
configuration: configuration,
|
||||
shops: shops,
|
||||
|
@ -207,6 +215,7 @@ class _ShopContents extends StatelessWidget {
|
|||
child: Column(
|
||||
children: [
|
||||
// Products
|
||||
|
||||
getCategoryList(
|
||||
context,
|
||||
configuration,
|
||||
|
@ -227,6 +236,11 @@ class _ShopContents extends StatelessWidget {
|
|||
children: [
|
||||
// Discounted product
|
||||
if (discountedproducts.isNotEmpty) ...[
|
||||
configuration.discountBuilder?.call(
|
||||
context,
|
||||
configuration,
|
||||
discountedproducts,
|
||||
) ??
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: WeeklyDiscount(
|
||||
|
@ -239,12 +253,17 @@ class _ShopContents extends StatelessWidget {
|
|||
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,
|
||||
),
|
||||
),
|
||||
|
||||
configuration.categoryListBuilder?.call(
|
||||
context,
|
||||
configuration,
|
||||
productPageContent,
|
||||
) ??
|
||||
productList,
|
||||
],
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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<Shop> 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<Product> discountedProducts,
|
||||
)? discountBuilder;
|
||||
|
||||
/// Builder for the list of items that are displayed in the product page.
|
||||
final Widget Function(
|
||||
BuildContext context,
|
||||
ProductPageConfiguration configuration,
|
||||
List<Product> products,
|
||||
)? categoryListBuilder;
|
||||
|
||||
/// Function that will be called when the order button on
|
||||
/// the shopping cart page is pressed
|
||||
final Function(List<Product>)? 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(
|
||||
|
|
|
@ -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!();
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue