feat: shopping interface (#10)

Co-authored-by: mike doornenbal <mikedoornenbal9@icloud.com>
This commit is contained in:
mike doornenbal 2024-07-02 14:31:41 +02:00 committed by GitHub
parent 5a24f7cf6f
commit ee377c107c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 237 additions and 0 deletions

View file

@ -1,3 +1,8 @@
## 2.0.0
- Added `flutter_shopping_interface` package
- Implemented default design
## 1.0.0 ## 1.0.0
- Initial version of the combined melos variant of the flutter_shopping user-story. - Initial version of the combined melos variant of the flutter_shopping user-story.

View file

@ -0,0 +1,9 @@
include: package:flutter_iconica_analysis/components_options.yaml
# Possible to overwrite the rules from the package
analyzer:
exclude:
linter:
rules:

View file

@ -0,0 +1,2 @@
export "src/model/model.dart";
export "src/service/service.dart";

View file

@ -0,0 +1,2 @@
export "product.dart";
export "shop.dart";

View file

@ -0,0 +1,85 @@
/// Product Interface
abstract class ProductInterface {
/// ProductInterface constructor
ProductInterface({
required this.id,
required this.name,
required this.imageUrl,
required this.category,
required this.price,
required this.description,
this.hasDiscount = false,
this.discountPrice,
this.quantity = 1,
});
/// Product id
final String id;
/// Product name
final String name;
/// Product image url
final String imageUrl;
/// Product category
final String category;
/// Product price
final double price;
/// whether the product has a discount
final bool hasDiscount;
/// Product discount price
final double? discountPrice;
/// Product quantity
int quantity;
/// Product description
final String description;
}
/// Product model
class Product implements ProductInterface {
/// Product constructor
Product({
required this.id,
required this.name,
required this.imageUrl,
required this.category,
required this.price,
required this.description,
this.hasDiscount = false,
this.discountPrice,
this.quantity = 1,
});
@override
final String id;
@override
final String name;
@override
final String imageUrl;
@override
final String category;
@override
final double price;
@override
final bool hasDiscount;
@override
final double? discountPrice;
@override
int quantity;
@override
final String description;
}

View file

@ -0,0 +1,28 @@
/// Shop interface
abstract class ShopInterface {
/// ShopInterface constructor
const ShopInterface({
required this.id,
required this.name,
});
/// Shop id
final int id;
/// Shop name
final String name;
}
/// Shop model
class Shop implements ShopInterface {
/// Shop constructor
const Shop({
required this.id,
required this.name,
});
@override
final int id;
@override
final String name;
}

View file

@ -0,0 +1,12 @@
import "package:flutter_shopping_interface/src/model/product.dart";
/// Order service
// ignore: one_member_abstracts
abstract class OrderService {
/// Create an order
Future<void> createOrder(
int shopId,
List<Product> products,
Map<String, dynamic> clientInformation,
);
}

View file

@ -0,0 +1,14 @@
import "package:flutter/material.dart";
import "package:flutter_shopping_interface/src/model/product.dart";
/// Product service
abstract class ProductService with ChangeNotifier {
/// Retrieve a list of products
Future<List<Product>> getProducts(int shopId);
/// Retrieve a product
Future<Product> getProduct(int id);
/// Retrieve a list of categories
List<String> getCategories();
}

View file

@ -0,0 +1,5 @@
export "order_service.dart";
export "product_service.dart";
export "shop_service.dart";
export "shopping_cart_service.dart";
export "shopping_service.dart";

View file

@ -0,0 +1,9 @@
import "package:flutter/material.dart";
import "package:flutter_shopping_interface/src/model/shop.dart";
/// Shop service
// ignore: one_member_abstracts
abstract class ShopService with ChangeNotifier {
/// Retrieve a list of shops
Future<List<Shop>> getShops();
}

View file

@ -0,0 +1,20 @@
import "package:flutter/material.dart";
import "package:flutter_shopping_interface/src/model/product.dart";
/// shopping cart service
abstract class ShoppingCartService with ChangeNotifier {
/// Adds a product to the shopping cart.
void addProduct(Product product);
/// Removes a product from the shopping cart.
void removeProduct(Product product);
/// Removes one product from the shopping cart.
void removeOneProduct(Product product);
/// Counts the number of products in the shopping cart.
int countProducts();
/// Clears the shopping cart.
void clear();
}

View file

@ -0,0 +1,24 @@
import "package:flutter_shopping_interface/src/service/service.dart";
/// Shopping service
class ShoppingService {
/// Shopping service constructor
const ShoppingService({
required this.orderService,
required this.productService,
required this.shopService,
required this.shoppingCartService,
});
/// Order service
final OrderService orderService;
/// Product service
final ProductService productService;
/// Shop service
final ShopService shopService;
/// Shopping cart service
final ShoppingCartService shoppingCartService;
}

View file

@ -0,0 +1,22 @@
name: flutter_shopping_interface
description: "A 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
dev_dependencies:
flutter_test:
sdk: flutter
flutter_iconica_analysis:
git:
url: https://github.com/Iconica-Development/flutter_iconica_analysis
ref: 7.0.0
flutter: