diff --git a/packages/flutter_shopping_interface/lib/src/model/shop.dart b/packages/flutter_shopping_interface/lib/src/model/shop.dart index 2e63671..b85dd6c 100644 --- a/packages/flutter_shopping_interface/lib/src/model/shop.dart +++ b/packages/flutter_shopping_interface/lib/src/model/shop.dart @@ -7,7 +7,7 @@ abstract class ShopInterface { }); /// Shop id - final int id; + final String id; /// Shop name final String name; @@ -21,7 +21,7 @@ class Shop implements ShopInterface { required this.name, }); @override - final int id; + final String id; @override final String name; diff --git a/packages/flutter_shopping_interface/lib/src/service/product_service.dart b/packages/flutter_shopping_interface/lib/src/service/product_service.dart index 073b32d..80bc20f 100644 --- a/packages/flutter_shopping_interface/lib/src/service/product_service.dart +++ b/packages/flutter_shopping_interface/lib/src/service/product_service.dart @@ -4,10 +4,10 @@ import "package:flutter_shopping_interface/src/model/product.dart"; /// Product service abstract class ProductService with ChangeNotifier { /// Retrieve a list of products - Future> getProducts(int shopId); + Future> getProducts(String shopId); /// Retrieve a product - Future getProduct(int id); + Future getProduct(String id); /// Retrieve a list of categories List getCategories(); diff --git a/packages/flutter_shopping_interface/lib/src/service/shop_service.dart b/packages/flutter_shopping_interface/lib/src/service/shop_service.dart index 8b2403d..205f4c4 100644 --- a/packages/flutter_shopping_interface/lib/src/service/shop_service.dart +++ b/packages/flutter_shopping_interface/lib/src/service/shop_service.dart @@ -6,4 +6,10 @@ import "package:flutter_shopping_interface/src/model/shop.dart"; abstract class ShopService with ChangeNotifier { /// Retrieve a list of shops Future> getShops(); + + /// Select a shop + void selectShop(Shop shop); + + /// The currently selected shop + Shop? get selectedShop; } diff --git a/packages/flutter_shopping_local/analysis_options.yaml b/packages/flutter_shopping_local/analysis_options.yaml new file mode 100644 index 0000000..0736605 --- /dev/null +++ b/packages/flutter_shopping_local/analysis_options.yaml @@ -0,0 +1,9 @@ +include: package:flutter_iconica_analysis/components_options.yaml + +# Possible to overwrite the rules from the package + +analyzer: + exclude: + +linter: + rules: diff --git a/packages/flutter_shopping_local/lib/flutter_shopping_local.dart b/packages/flutter_shopping_local/lib/flutter_shopping_local.dart new file mode 100644 index 0000000..44941b5 --- /dev/null +++ b/packages/flutter_shopping_local/lib/flutter_shopping_local.dart @@ -0,0 +1 @@ +export "service/service.dart"; diff --git a/packages/flutter_shopping_local/lib/service/local_order_service.dart b/packages/flutter_shopping_local/lib/service/local_order_service.dart new file mode 100644 index 0000000..190e74f --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/local_order_service.dart @@ -0,0 +1,15 @@ +import "package:flutter/material.dart"; +import "package:flutter_shopping_interface/flutter_shopping_interface.dart"; + +/// Local order service +class LocalOrderService with ChangeNotifier implements OrderService { + @override + Future createOrder( + int shopId, + List products, + Map clientInformation, + ) { + // No use case for this method yet + throw UnimplementedError(); + } +} diff --git a/packages/flutter_shopping_local/lib/service/local_product_service.dart b/packages/flutter_shopping_local/lib/service/local_product_service.dart new file mode 100644 index 0000000..e276743 --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/local_product_service.dart @@ -0,0 +1,65 @@ +import "package:flutter/material.dart"; +import "package:flutter_shopping_interface/flutter_shopping_interface.dart"; + +/// Local product service +class LocalProductService with ChangeNotifier implements ProductService { + List _products = []; + + @override + List getCategories() => + _products.map((e) => e.category).toSet().toList(); + + @override + Future getProduct(String id) => + Future.value(_products.firstWhere((element) => element.id == id)); + + @override + Future> getProducts(String shopId) async { + await Future.delayed(const Duration(seconds: 1)); + _products = [ + Product( + id: "1", + name: "White Bread", + imageUrl: "https://firebasestorage.googleapis.com/v0/b/appshell-demo" + ".appspot.com/o/shopping%2Fwhite.png" + "?alt=media&token=e3aa13d5-932a-4119-bdbb-89c1a1d82213", + category: "Bread", + price: 1.0, + description: "This is a delicious white bread", + hasDiscount: true, + discountPrice: 0.5, + ), + Product( + id: "2", + name: "Brown Bread", + imageUrl: "https://firebasestorage.googleapis.com/v0/b/appshell-" + "demo.appspot.com/o/shopping%2Fbrown.png?alt=media&" + "token=fbfe280d-44e6-4cde-a491-bcb7f598d22c", + category: "Bread", + price: 2.0, + description: "This is a delicious brown bread", + ), + Product( + id: "3", + name: "White fish", + imageUrl: "https://firebasestorage.googleapis.com/v0/b/appshell" + "-demo.appspot.com/o/shopping%2Fwhite-fish.png?alt=media" + "&token=61c44f84-347d-4b42-a10d-c172f167929b", + category: "Fish", + price: 1.5, + description: "This is a delicious white fish", + ), + Product( + id: "4", + name: "Brown fish", + imageUrl: "https://firebasestorage.googleapis.com/v0/b/appshel" + "l-demo.appspot.com/o/shopping%2Fbrown-fish.png?alt=media&" + "token=b743a53c-c4bb-49ac-8894-a08132992902", + category: "Fish", + price: 1.5, + description: "This is a delicious Brown fish", + ), + ]; + return Future.value(_products); + } +} diff --git a/packages/flutter_shopping_local/lib/service/local_shop_service.dart b/packages/flutter_shopping_local/lib/service/local_shop_service.dart new file mode 100644 index 0000000..6c5a11a --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/local_shop_service.dart @@ -0,0 +1,35 @@ +import "package:flutter/material.dart"; +import "package:flutter_shopping_interface/flutter_shopping_interface.dart"; + +/// A service that provides a list of shops. +class LocalShopService with ChangeNotifier implements ShopService { + Shop? _selectedShop; + + @override + Future> getShops() async { + await Future.delayed(const Duration(seconds: 1)); + var shops = [ + const Shop(id: "1", name: "Bakkerij de Goudkorst"), + const Shop(id: "2", name: "Slagerij PuurVlees"), + const Shop(id: "3", name: "De GroenteHut"), + const Shop(id: "4", name: "Pizzeria Ciao"), + const Shop(id: "5", name: "Cafetaria Roos"), + const Shop(id: "6", name: "Zeebries Visdelicatessen"), + const Shop(id: "7", name: "De Oosterse Draak"), + ]; + return Future.value(shops); + } + + /// Updates the selected shop. + @override + void selectShop(Shop shop) { + if (_selectedShop == shop) return; + + _selectedShop = shop; + notifyListeners(); + } + + /// The currently selected shop. + @override + Shop? get selectedShop => _selectedShop; +} diff --git a/packages/flutter_shopping_local/lib/service/local_shopping_cart_service.dart b/packages/flutter_shopping_local/lib/service/local_shopping_cart_service.dart new file mode 100644 index 0000000..dafa160 --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/local_shopping_cart_service.dart @@ -0,0 +1,57 @@ +import "package:flutter/material.dart"; +import "package:flutter_shopping_interface/flutter_shopping_interface.dart"; + +/// Local shopping cart service +class LocalShoppingCartService + with ChangeNotifier + implements ShoppingCartService { + final List _products = []; + @override + void addProduct(Product product) { + if (_products.contains(product)) { + var index = _products.indexOf(product); + _products[index].quantity++; + } else { + _products.add(product); + } + notifyListeners(); + } + + @override + void clear() { + _products.clear(); + notifyListeners(); + } + + @override + int countProducts() { + var count = 0; + for (var product in _products) { + count += product.quantity; + } + notifyListeners(); + return count; + } + + @override + void removeOneProduct(Product product) { + if (_products.contains(product)) { + var index = _products.indexOf(product); + if (_products[index].quantity > 1) { + _products[index].quantity--; + } else { + _products.removeAt(index); + } + } + notifyListeners(); + } + + @override + void removeProduct(Product product) { + if (_products.contains(product)) { + var index = _products.indexOf(product); + _products.removeAt(index); + } + notifyListeners(); + } +} diff --git a/packages/flutter_shopping_local/lib/service/local_shopping_service.dart b/packages/flutter_shopping_local/lib/service/local_shopping_service.dart new file mode 100644 index 0000000..ef91410 --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/local_shopping_service.dart @@ -0,0 +1,45 @@ +import "package:flutter_shopping_interface/flutter_shopping_interface.dart"; +import "package:flutter_shopping_local/service/local_order_service.dart"; +import "package:flutter_shopping_local/service/local_product_service.dart"; +import "package:flutter_shopping_local/service/local_shop_service.dart"; +import "package:flutter_shopping_local/service/local_shopping_cart_service.dart"; + +/// Local shopping service +class LocalShoppingService implements ShoppingService { + /// Local shopping service constructor + LocalShoppingService({ + this.localOrderService, + this.localShopService, + this.localProductService, + this.localShoppingCartService, + }) { + localOrderService ??= LocalOrderService(); + localShopService ??= LocalShopService(); + localProductService ??= LocalProductService(); + localShoppingCartService ??= LocalShoppingCartService(); + } + + /// Local order service + OrderService? localOrderService; + + /// Local shop service + ShopService? localShopService; + + /// Local product service + ProductService? localProductService; + + /// Local shopping cart service + ShoppingCartService? localShoppingCartService; + + @override + OrderService get orderService => localOrderService!; + + @override + ProductService get productService => localProductService!; + + @override + ShopService get shopService => localShopService!; + + @override + ShoppingCartService get shoppingCartService => localShoppingCartService!; +} diff --git a/packages/flutter_shopping_local/lib/service/service.dart b/packages/flutter_shopping_local/lib/service/service.dart new file mode 100644 index 0000000..e974132 --- /dev/null +++ b/packages/flutter_shopping_local/lib/service/service.dart @@ -0,0 +1 @@ +export "local_shop_service.dart"; diff --git a/packages/flutter_shopping_local/pubspec.yaml b/packages/flutter_shopping_local/pubspec.yaml new file mode 100644 index 0000000..a4c1521 --- /dev/null +++ b/packages/flutter_shopping_local/pubspec.yaml @@ -0,0 +1,28 @@ +name: flutter_shopping_local +description: "A local Flutter module for a shopping." +version: 2.0.0 +publish_to: 'none' + +environment: + sdk: '>=3.3.0 <4.0.0' + flutter: ">=1.17.0" + +dependencies: + flutter: + sdk: flutter + flutter_shopping_interface: + git: + url: https://github.com/Iconica-Development/flutter_shopping + path: packages/flutter_shopping_interface + ref: 2.0.0 + + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_iconica_analysis: + git: + url: https://github.com/Iconica-Development/flutter_iconica_analysis + ref: 7.0.0 + +flutter: \ No newline at end of file