parent
84222618d5
commit
c061e361eb
@ -0,0 +1,31 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:thesis_shop/models/product.dart'; |
||||||
|
|
||||||
|
class ProductSelectionStore extends InheritedWidget { |
||||||
|
const ProductSelectionStore({ |
||||||
|
Key? key, |
||||||
|
required this.products, |
||||||
|
required this.productAmounts, |
||||||
|
required this.increaseAmount, |
||||||
|
required this.decreaseAmount, |
||||||
|
required Widget child, |
||||||
|
}) : super(key: key, child: child); |
||||||
|
|
||||||
|
final List<Product> products; |
||||||
|
final Map<ProductTitle, int> productAmounts; |
||||||
|
|
||||||
|
final Function(Product) increaseAmount; |
||||||
|
final Function(Product) decreaseAmount; |
||||||
|
|
||||||
|
static ProductSelectionStore of(BuildContext context) { |
||||||
|
final ProductSelectionStore? result = |
||||||
|
context.dependOnInheritedWidgetOfExactType<ProductSelectionStore>(); |
||||||
|
assert(result != null, 'No ProductSelectionStore found in context'); |
||||||
|
return result!; |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
bool updateShouldNotify(ProductSelectionStore oldWidget) { |
||||||
|
return productAmounts != oldWidget.productAmounts; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue