mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 08:44:06 +02:00
move product model and coordinate model into models/
This commit is contained in:
parent
18170b5364
commit
86100a103a
@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
|
|||||||
return MultiProvider(
|
return MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
ChangeNotifierProvider(create: (_) => Routing()),
|
ChangeNotifierProvider(create: (_) => Routing()),
|
||||||
ChangeNotifierProvider(create: (_) => ProductRepo()),
|
ChangeNotifierProvider(create: (_) => ProductRepoByMemory()),
|
||||||
ChangeNotifierProvider(create: (_) => CartRepo()),
|
ChangeNotifierProvider(create: (_) => CartRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
ChangeNotifierProvider(create: (_) => ReceiptRepo()),
|
||||||
ChangeNotifierProvider(create: (_) => PayingStateRepo()),
|
ChangeNotifierProvider(create: (_) => PayingStateRepo()),
|
||||||
|
6
mobile/lib/models/coordinate.dart
Normal file
6
mobile/lib/models/coordinate.dart
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class Coordinate {
|
||||||
|
final double x;
|
||||||
|
final double y;
|
||||||
|
|
||||||
|
Coordinate({required this.x, required this.y});
|
||||||
|
}
|
19
mobile/lib/models/product.dart
Normal file
19
mobile/lib/models/product.dart
Normal file
@ -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,
|
||||||
|
});
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/repos/product.dart';
|
||||||
import 'package:mobile/utils/price.dart';
|
import 'package:mobile/utils/price.dart';
|
||||||
import 'package:mobile/widgets/sized_card.dart';
|
import 'package:mobile/widgets/sized_card.dart';
|
||||||
@ -98,7 +99,7 @@ class AllProductsPage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final productRepo = Provider.of<ProductRepo>(context);
|
final productRepo = Provider.of<ProductRepoByMemory>(context);
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
@ -121,7 +122,8 @@ class AllProductsPage extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Consumer<ProductRepo>(builder: (_, productRepo, __) {
|
child:
|
||||||
|
Consumer<ProductRepoByMemory>(builder: (_, productRepo, __) {
|
||||||
final products = productRepo.filteredProducts;
|
final products = productRepo.filteredProducts;
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
|
@ -2,6 +2,7 @@ import 'package:barcode_scan2/model/android_options.dart';
|
|||||||
import 'package:barcode_scan2/model/scan_options.dart';
|
import 'package:barcode_scan2/model/scan_options.dart';
|
||||||
import 'package:barcode_scan2/platform_wrapper.dart';
|
import 'package:barcode_scan2/platform_wrapper.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/pages/finish_shopping_page.dart';
|
import 'package:mobile/pages/finish_shopping_page.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/repos/product.dart';
|
||||||
@ -204,8 +205,9 @@ class CartPage extends StatelessWidget {
|
|||||||
child: const Text("Cancel")),
|
child: const Text("Cancel")),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final ProductRepo productRepo =
|
final ProductRepoByMemory
|
||||||
context.read<ProductRepo>();
|
productRepo = context.read<
|
||||||
|
ProductRepoByMemory>();
|
||||||
final CartRepo cartRepo =
|
final CartRepo cartRepo =
|
||||||
context.read<CartRepo>();
|
context.read<CartRepo>();
|
||||||
final productResult =
|
final productResult =
|
||||||
@ -269,8 +271,8 @@ class CartPage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
final CartRepo cartRepo =
|
final CartRepo cartRepo =
|
||||||
context.read<CartRepo>();
|
context.read<CartRepo>();
|
||||||
final ProductRepo productRepo =
|
final ProductRepoByMemory productRepo =
|
||||||
context.read<ProductRepo>();
|
context.read<ProductRepoByMemory>();
|
||||||
final productResult = productRepo
|
final productResult = productRepo
|
||||||
.productWithBarcode(result.rawContent);
|
.productWithBarcode(result.rawContent);
|
||||||
switch (productResult) {
|
switch (productResult) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
import 'package:flutter/material.dart';
|
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/location_image.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class ProductLocationPage extends StatelessWidget {
|
class ProductLocationPage extends StatelessWidget {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/pages/product_location_page.dart';
|
import 'package:mobile/pages/product_location_page.dart';
|
||||||
import 'package:mobile/repos/add_to_cart_state.dart';
|
import 'package:mobile/repos/add_to_cart_state.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
|
||||||
import 'package:mobile/utils/price.dart';
|
import 'package:mobile/utils/price.dart';
|
||||||
import 'package:mobile/widgets/primary_button.dart';
|
import 'package:mobile/widgets/primary_button.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/models/product.dart';
|
||||||
|
|
||||||
class ProductIdException implements Exception {}
|
class ProductIdException implements Exception {}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/models/coordinate.dart';
|
||||||
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/results.dart';
|
import 'package:mobile/results.dart';
|
||||||
|
|
||||||
class ProductRepo extends ChangeNotifier {
|
class ProductRepoByMemory extends ChangeNotifier {
|
||||||
int _nextId = 0;
|
int _nextId = 0;
|
||||||
List<Product> products = [];
|
List<Product> products = [];
|
||||||
late List<Product> filteredProducts;
|
late List<Product> filteredProducts;
|
||||||
ProductRepo() {
|
ProductRepoByMemory() {
|
||||||
_addAllProducts();
|
_addAllProducts();
|
||||||
filteredProducts = products;
|
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:mobile/models/product.dart';
|
||||||
import 'package:mobile/repos/cart.dart';
|
import 'package:mobile/repos/cart.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
|
||||||
|
|
||||||
class ReceiptRepo extends ChangeNotifier {
|
class ReceiptRepo extends ChangeNotifier {
|
||||||
int nextId = 0;
|
int nextId = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user