mirror of
https://github.com/Iconica-Development/flutter_shopping.git
synced 2025-05-19 08:53:46 +02:00
fix: add popup to shopping cart
This commit is contained in:
parent
c2b70eca3d
commit
d5309b8198
4 changed files with 86 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
import "package:flutter/material.dart";
|
||||
import "package:flutter_shopping/flutter_shopping.dart";
|
||||
import "package:flutter_shopping_cart/src/widgets/product_item_popup.dart";
|
||||
|
||||
Widget _defaultNoContentBuilder(BuildContext context) =>
|
||||
const SizedBox.shrink();
|
||||
|
@ -53,6 +54,7 @@ you must use the onConfirmOrder callback.""",
|
|||
Locale locale,
|
||||
Product product,
|
||||
ProductService<Product> productService,
|
||||
ShoppingCartConfig configuration,
|
||||
) productItemBuilder;
|
||||
|
||||
final Widget Function(BuildContext context) _noContentBuilder;
|
||||
|
@ -115,6 +117,7 @@ Widget _defaultProductItemBuilder(
|
|||
Locale locale,
|
||||
Product product,
|
||||
ProductService<Product> service,
|
||||
ShoppingCartConfig configuration,
|
||||
) {
|
||||
var theme = Theme.of(context);
|
||||
return Padding(
|
||||
|
@ -128,9 +131,18 @@ Widget _defaultProductItemBuilder(
|
|||
product.name,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: theme.colorScheme.primary,
|
||||
IconButton(
|
||||
onPressed: () async {
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: theme.colorScheme.surface,
|
||||
builder: (context) => ProductItemPopup(product: product, configuration: configuration)
|
||||
);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.info_outline,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -8,6 +8,7 @@ class ShoppingCartLocalizations {
|
|||
this.placeOrder = "Order",
|
||||
this.sum = "Subtotal:",
|
||||
this.cartTitle = "Products",
|
||||
this.close = "close",
|
||||
});
|
||||
|
||||
/// 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
|
||||
/// the shopping cart.
|
||||
final String cartTitle;
|
||||
|
||||
/// Localization for the close button for the popup.
|
||||
final String close;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -54,6 +54,7 @@ class ShoppingCartScreen<T extends Product> extends StatelessWidget {
|
|||
configuration.localizations.locale,
|
||||
product,
|
||||
configuration.productService,
|
||||
configuration,
|
||||
),
|
||||
// Additional whitespace at the bottom to make sure the
|
||||
// last product(s) are not hidden by the bottom sheet.
|
||||
|
@ -216,7 +217,7 @@ class _DefaultSumBottomSheet extends StatelessWidget {
|
|||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
totalPrice.toStringAsFixed(2),
|
||||
"€ ${totalPrice.toStringAsFixed(2)}",
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue