fix: add popup to shopping cart

This commit is contained in:
mike doornenbal 2024-06-27 14:29:35 +02:00
parent c2b70eca3d
commit d5309b8198
4 changed files with 86 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import "package:flutter/material.dart"; import "package:flutter/material.dart";
import "package:flutter_shopping/flutter_shopping.dart"; import "package:flutter_shopping/flutter_shopping.dart";
import "package:flutter_shopping_cart/src/widgets/product_item_popup.dart";
Widget _defaultNoContentBuilder(BuildContext context) => Widget _defaultNoContentBuilder(BuildContext context) =>
const SizedBox.shrink(); const SizedBox.shrink();
@ -53,6 +54,7 @@ you must use the onConfirmOrder callback.""",
Locale locale, Locale locale,
Product product, Product product,
ProductService<Product> productService, ProductService<Product> productService,
ShoppingCartConfig configuration,
) productItemBuilder; ) productItemBuilder;
final Widget Function(BuildContext context) _noContentBuilder; final Widget Function(BuildContext context) _noContentBuilder;
@ -115,6 +117,7 @@ Widget _defaultProductItemBuilder(
Locale locale, Locale locale,
Product product, Product product,
ProductService<Product> service, ProductService<Product> service,
ShoppingCartConfig configuration,
) { ) {
var theme = Theme.of(context); var theme = Theme.of(context);
return Padding( return Padding(
@ -128,10 +131,19 @@ Widget _defaultProductItemBuilder(
product.name, product.name,
style: theme.textTheme.titleMedium, style: theme.textTheme.titleMedium,
), ),
Icon( IconButton(
onPressed: () async {
await showModalBottomSheet(
context: context,
backgroundColor: theme.colorScheme.surface,
builder: (context) => ProductItemPopup(product: product, configuration: configuration)
);
},
icon: Icon(
Icons.info_outline, Icons.info_outline,
color: theme.colorScheme.primary, color: theme.colorScheme.primary,
), ),
),
], ],
), ),
leading: ClipRRect( leading: ClipRRect(

View file

@ -8,6 +8,7 @@ class ShoppingCartLocalizations {
this.placeOrder = "Order", this.placeOrder = "Order",
this.sum = "Subtotal:", this.sum = "Subtotal:",
this.cartTitle = "Products", this.cartTitle = "Products",
this.close = "close",
}); });
/// Locale for the shopping cart. /// Locale for the shopping cart.
@ -26,4 +27,7 @@ class ShoppingCartLocalizations {
/// Title for the shopping cart. This title will be displayed at the top of /// Title for the shopping cart. This title will be displayed at the top of
/// the shopping cart. /// the shopping cart.
final String cartTitle; final String cartTitle;
/// Localization for the close button for the popup.
final String close;
} }

View file

@ -0,0 +1,65 @@
import "package:flutter/material.dart";
import "package:flutter_shopping/flutter_shopping.dart";
/// A popup that displays the product item.
class ProductItemPopup extends StatelessWidget {
/// Constructor for the product item popup.
const ProductItemPopup({
required this.product,
required this.configuration,
super.key,
});
/// The product to display.
final Product product;
/// Configuration for the product page.
final ShoppingCartConfig configuration;
@override
Widget build(BuildContext context) {
var theme = Theme.of(context);
return SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(32),
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Text(
product.description,
style: theme.textTheme.bodySmall,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(top: 20, left: 40, right: 40),
child: SizedBox(
width: double.infinity,
child: FilledButton(
onPressed: () => Navigator.of(context).pop(),
style: theme.filledButtonTheme.style?.copyWith(
backgroundColor: WidgetStateProperty.all(
theme.colorScheme.primary,
),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Text(
configuration.localizations.close,
style: theme.textTheme.displayLarge,
),
),
),
),
),
],
),
),
),
);
}
}

View file

@ -54,6 +54,7 @@ class ShoppingCartScreen<T extends Product> extends StatelessWidget {
configuration.localizations.locale, configuration.localizations.locale,
product, product,
configuration.productService, configuration.productService,
configuration,
), ),
// Additional whitespace at the bottom to make sure the // Additional whitespace at the bottom to make sure the
// last product(s) are not hidden by the bottom sheet. // last product(s) are not hidden by the bottom sheet.
@ -216,7 +217,7 @@ class _DefaultSumBottomSheet extends StatelessWidget {
), ),
const Spacer(), const Spacer(),
Text( Text(
totalPrice.toStringAsFixed(2), "${totalPrice.toStringAsFixed(2)}",
style: theme.textTheme.bodyMedium, style: theme.textTheme.bodyMedium,
), ),
], ],