diff --git a/mobile/lib/main.dart b/mobile/lib/main.dart index d293389..6b14f45 100644 --- a/mobile/lib/main.dart +++ b/mobile/lib/main.dart @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget { return MultiProvider( providers: [ ChangeNotifierProvider(create: (_) => Routing()), - ChangeNotifierProvider(create: (_) => ProductRepo()), + ChangeNotifierProvider(create: (_) => ProductRepoByMemory()), ChangeNotifierProvider(create: (_) => CartRepo()), ChangeNotifierProvider(create: (_) => ReceiptRepo()), ChangeNotifierProvider(create: (_) => PayingStateRepo()), diff --git a/mobile/lib/models/coordinate.dart b/mobile/lib/models/coordinate.dart new file mode 100644 index 0000000..fd285ff --- /dev/null +++ b/mobile/lib/models/coordinate.dart @@ -0,0 +1,6 @@ +class Coordinate { + final double x; + final double y; + + Coordinate({required this.x, required this.y}); +} diff --git a/mobile/lib/models/product.dart b/mobile/lib/models/product.dart new file mode 100644 index 0000000..faefcd0 --- /dev/null +++ b/mobile/lib/models/product.dart @@ -0,0 +1,19 @@ +import 'package:mobile/models/coordinate.dart'; + +class Product { + final int id; + final String name; + final String description; + final int priceInDkkCent; + final Coordinate? location; + final String? barcode; + + Product({ + required this.id, + required this.name, + required this.priceInDkkCent, + required this.description, + this.location, + this.barcode, + }); +} diff --git a/mobile/lib/pages/all_products_page.dart b/mobile/lib/pages/all_products_page.dart index 5cc28f2..3bf8de5 100644 --- a/mobile/lib/pages/all_products_page.dart +++ b/mobile/lib/pages/all_products_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/repos/product.dart'; import 'package:mobile/utils/price.dart'; import 'package:mobile/widgets/sized_card.dart'; @@ -98,7 +99,7 @@ class AllProductsPage extends StatelessWidget { @override Widget build(BuildContext context) { - final productRepo = Provider.of(context); + final productRepo = Provider.of(context); return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -121,7 +122,8 @@ class AllProductsPage extends StatelessWidget { ], ), Expanded( - child: Consumer(builder: (_, productRepo, __) { + child: + Consumer(builder: (_, productRepo, __) { final products = productRepo.filteredProducts; return ListView.builder( shrinkWrap: true, diff --git a/mobile/lib/pages/cart_page.dart b/mobile/lib/pages/cart_page.dart index 5f20636..7f64b48 100644 --- a/mobile/lib/pages/cart_page.dart +++ b/mobile/lib/pages/cart_page.dart @@ -2,6 +2,7 @@ import 'package:barcode_scan2/model/android_options.dart'; import 'package:barcode_scan2/model/scan_options.dart'; import 'package:barcode_scan2/platform_wrapper.dart'; import 'package:flutter/material.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/pages/finish_shopping_page.dart'; import 'package:mobile/repos/cart.dart'; import 'package:mobile/repos/product.dart'; @@ -204,8 +205,9 @@ class CartPage extends StatelessWidget { child: const Text("Cancel")), TextButton( onPressed: () { - final ProductRepo productRepo = - context.read(); + final ProductRepoByMemory + productRepo = context.read< + ProductRepoByMemory>(); final CartRepo cartRepo = context.read(); final productResult = @@ -269,8 +271,8 @@ class CartPage extends StatelessWidget { } final CartRepo cartRepo = context.read(); - final ProductRepo productRepo = - context.read(); + final ProductRepoByMemory productRepo = + context.read(); final productResult = productRepo .productWithBarcode(result.rawContent); switch (productResult) { diff --git a/mobile/lib/pages/product_location_page.dart b/mobile/lib/pages/product_location_page.dart index 777071c..82a25f1 100644 --- a/mobile/lib/pages/product_location_page.dart +++ b/mobile/lib/pages/product_location_page.dart @@ -1,7 +1,8 @@ import 'dart:ui' as ui; import 'package:flutter/material.dart'; +import 'package:mobile/models/coordinate.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/repos/location_image.dart'; -import 'package:mobile/repos/product.dart'; import 'package:provider/provider.dart'; class ProductLocationPage extends StatelessWidget { diff --git a/mobile/lib/pages/product_page.dart b/mobile/lib/pages/product_page.dart index 060c2df..6861f95 100644 --- a/mobile/lib/pages/product_page.dart +++ b/mobile/lib/pages/product_page.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/pages/product_location_page.dart'; import 'package:mobile/repos/add_to_cart_state.dart'; import 'package:mobile/repos/cart.dart'; -import 'package:mobile/repos/product.dart'; import 'package:mobile/utils/price.dart'; import 'package:mobile/widgets/primary_button.dart'; import 'package:provider/provider.dart'; diff --git a/mobile/lib/repos/cart.dart b/mobile/lib/repos/cart.dart index 6c9420e..5a6e483 100644 --- a/mobile/lib/repos/cart.dart +++ b/mobile/lib/repos/cart.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:mobile/repos/product.dart'; +import 'package:mobile/models/product.dart'; class ProductIdException implements Exception {} diff --git a/mobile/lib/repos/product.dart b/mobile/lib/repos/product.dart index 058a379..839ad64 100644 --- a/mobile/lib/repos/product.dart +++ b/mobile/lib/repos/product.dart @@ -1,11 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:mobile/models/coordinate.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/results.dart'; -class ProductRepo extends ChangeNotifier { +class ProductRepoByMemory extends ChangeNotifier { int _nextId = 0; List products = []; late List filteredProducts; - ProductRepo() { + ProductRepoByMemory() { _addAllProducts(); filteredProducts = products; } @@ -123,28 +125,3 @@ class ProductRepo extends ChangeNotifier { ]; } } - -class Coordinate { - final double x; - final double y; - - Coordinate({required this.x, required this.y}); -} - -class Product { - final int id; - final String name; - final String description; - final int priceInDkkCent; - final Coordinate? location; - final String? barcode; - - Product({ - required this.id, - required this.name, - required this.priceInDkkCent, - required this.description, - this.location, - this.barcode, - }); -} diff --git a/mobile/lib/repos/receipt.dart b/mobile/lib/repos/receipt.dart index b72e22d..b89c5d2 100644 --- a/mobile/lib/repos/receipt.dart +++ b/mobile/lib/repos/receipt.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:mobile/models/product.dart'; import 'package:mobile/repos/cart.dart'; -import 'package:mobile/repos/product.dart'; class ReceiptRepo extends ChangeNotifier { int nextId = 0;