Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes/back hero animation #141

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ecommers/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"fieldError": "field should not be empty.",
"notificationsTitle": "Notifications",
"yesterday": "Yesterday",
"empty": "",
"delete": "Delete",
"notBankCards": "You have no credit cards added",
"paymentMethodTitle":"Payment Method",
Expand All @@ -80,5 +79,7 @@
"exprDatePlaceHolder": "05/23",
"cvc": "CVC",
"addCardDetails": "ADD CARD DETAILS",
"selectCreditCard": "Select credit card"
"selectCreditCard": "Select credit card",
"messageToSeller" : "Message to seller (optional)",
"empty": ""
}
8 changes: 4 additions & 4 deletions ecommers/lib/core/app_services/payment_method_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:ecommers/core/models/cache_wrappers/payment_method_wrapper.dart';
import 'package:ecommers/core/models/payment_method_model.dart';
import 'package:ecommers/core/models/payment_method_wrapper.dart';
import 'package:ecommers/core/services/dependency_service.dart';
import 'package:stripe_payment/stripe_payment.dart';

Expand Down Expand Up @@ -33,7 +33,7 @@ class PaymentMethodService {
final paymentMethodModel =
PaymentMethodModel.fromStripePaymentMethod(paymentMethod);

await paymentMethodRepository.addPaymentMethod(
await paymentMethodRepository.add(
PaymentMethodWrapper.fromPaymentMethod(paymentMethodModel),
);

Expand All @@ -44,13 +44,13 @@ class PaymentMethodService {
}

Future removePaymentMethod(PaymentMethodModel paymentMethodModel) async {
await paymentMethodRepository.removePaymentMethod(
await paymentMethodRepository.remove(
PaymentMethodWrapper.fromPaymentMethod(paymentMethodModel),
);
}

Future editPaymentMethod(PaymentMethodModel paymentMethodModel) async {
await paymentMethodRepository.editPaymentMethod(
await paymentMethodRepository.edit(
PaymentMethodWrapper.fromPaymentMethod(paymentMethodModel),
);
}
Expand Down
1 change: 1 addition & 0 deletions ecommers/lib/core/common/cache_defines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class CacheDefines {
static const String categories = 'categories';
static const String latestProducts = 'latestProducts';
static const String paymentMethods = 'paymentMethods';
static const String orders = 'orders';
}
32 changes: 32 additions & 0 deletions ecommers/lib/core/models/cache_wrappers/order_model_wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:ecommers/core/models/cache_wrappers/wrapper.dart';
import 'package:ecommers/core/models/index.dart';
import 'package:ecommers/core/services/index.dart';
import 'package:json_annotation/json_annotation.dart';

part 'order_model_wrapper.g.dart';

@JsonSerializable()
class OrderModelWrapper implements Wrapper{
@override
final int id;
final int userId;
final OrderModel order;

OrderModelWrapper({
this.id,
this.userId,
this.order,
});

factory OrderModelWrapper.fromOrderModel(
OrderModel order) {
return OrderModelWrapper(
id: order.product.id,
userId: membershipService.id,
order: order,
);
}
static const fromJson = _$OrderModelWrapperFromJson;

Map<String, dynamic> toJson() => _$OrderModelWrapperToJson(this);
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:ecommers/core/models/cache_wrappers/wrapper.dart';
import 'package:ecommers/core/models/payment_method_model.dart';
import 'package:ecommers/core/services/dependency_service.dart';
import 'package:json_annotation/json_annotation.dart';

part 'payment_method_wrapper.g.dart';

@JsonSerializable()
class PaymentMethodWrapper {
class PaymentMethodWrapper implements Wrapper{
@override
final String id;
final int userId;
final PaymentMethodModel paymentMethodModel;
Expand Down
5 changes: 5 additions & 0 deletions ecommers/lib/core/models/cache_wrappers/wrapper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Wrapper {
final dynamic id;

Wrapper(this.id);
}
27 changes: 9 additions & 18 deletions ecommers/lib/core/models/order_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,24 @@ part 'order_model.g.dart';

@JsonSerializable()
class OrderModel {
final int id;
final String title;
final String description;
final String imagePath;
final double cost;
final Product product;
final String characteristics;
int count;

OrderModel({
this.id,
this.description,
this.cost,
this.imagePath,
this.title,
this.count,
this.product,
this.characteristics,
this.count = 1,
});

static const fromJson = _$OrderModelFromJson;

factory OrderModel.fromProduct(Product product) {
factory OrderModel.fromProduct({Product product, String size, String color}) {
return OrderModel(
id: product.id,
imagePath: product.previewImage,
title: product.title,
cost: product.price,
description: 'Medium, Green 3',
product: product,
characteristics: '$size, $color',
count: 1,
); //todo change mapping after refactoring productPage
);
}

Map<String, dynamic> toJson() => _$OrderModelToJson(this);
Expand Down
2 changes: 2 additions & 0 deletions ecommers/lib/core/models/product_color_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'package:meta/meta.dart';
class ProductColorModel {
bool isSelected;
final int color;
final String title;
final List<CarouselImage> images;

ProductColorModel({
@required this.color,
@required this.images,
this.isSelected = false,
this.title,
});
}
17 changes: 9 additions & 8 deletions ecommers/lib/core/provider_models/cart_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:ecommers/core/models/cache_wrappers/order_model_wrapper.dart';
import 'package:ecommers/core/models/index.dart';
import 'package:ecommers/core/services/dependency_service.dart';
import 'package:flutter/widgets.dart';
Expand All @@ -9,31 +10,31 @@ class CartProvider extends ChangeNotifier {
int get orderCount => _orders.length;

Future remove(OrderModel order, {int count = 1}) async {
final editOrder = _getOrder(order.id);
final editOrder = _getOrder(order.product.id);

if (editOrder == null) {
return;
}

if (editOrder.count > count) {
editOrder.count = editOrder.count - count;
await cartRepository.editOrder(order);
await cartRepository.edit(OrderModelWrapper.fromOrderModel(order));
} else {
_orders.remove(editOrder);
await cartRepository.removeOrder(order);
await cartRepository.remove(OrderModelWrapper.fromOrderModel(order));
}
notifyListeners();
}

Future add(OrderModel order) async {
final editOrder = _getOrder(order.id);
final editOrder = _getOrder(order.product.id);

if (editOrder == null) {
_orders.add(order);
await cartRepository.addOrder(order);
await cartRepository.add(OrderModelWrapper.fromOrderModel(order));
} else {
editOrder.count++;
await cartRepository.editOrder(order);
await cartRepository.edit(OrderModelWrapper.fromOrderModel(order));
}
notifyListeners();
}
Expand All @@ -52,7 +53,7 @@ class CartProvider extends ChangeNotifier {
final double totalCost = _orders.fold(
0.0,
(totalOrderCost, nextOrder) =>
totalOrderCost + nextOrder.count * nextOrder.cost);
totalOrderCost + nextOrder.count * nextOrder.product.price);

return totalCost * (100 - salePercent) / 100;
}
Expand All @@ -63,5 +64,5 @@ class CartProvider extends ChangeNotifier {
}

OrderModel _getOrder(int id) =>
_orders.firstWhere((o) => o.id == id, orElse: () => null);
_orders.firstWhere((o) => o.product.id == id, orElse: () => null);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:ecommers/core/common/index.dart';
import 'package:ecommers/core/models/payment_method_model.dart';
import 'package:ecommers/core/services/dependency_service.dart';
import 'package:flutter/material.dart';
Expand Down
22 changes: 19 additions & 3 deletions ecommers/lib/core/provider_models/product_page_provider_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import 'package:ecommers/ui/widgets/right_menu_bar/models/index.dart';
import 'package:flutter/widgets.dart';

class ProductPageProviderModel extends ProviderModelBase {
static const String undefineTagValue = 'undef';

final Product _productModel;
dynamic heroImageTag;

List<CarouselImage> _images;
List<CarouselImage> get images => _images;
Expand All @@ -24,30 +27,42 @@ class ProductPageProviderModel extends ProviderModelBase {
String get skuId => _skuId;
set skuId(String skuId) => _skuId = skuId ?? '';

String get selectSize => _sizes.firstWhere((element) => element.isSelected, orElse: () => sizes[0]).size;
String get selectColor => _colors.firstWhere((element) => element.isSelected, orElse: () => _colors[0]).title;

ProductPageProviderModel(this._productModel, {@required BuildContext context})
: super(context) {
_initProductImages();
_initProductTab();
_saveRecentProduct();
heroImageTag = _productModel.id;
}

void updateImages(List<CarouselImage> assets) {
images = assets;
notifyListeners();
}

void navigateToCart() {
const int shellCartIndex = 2;

heroImageTag = undefineTagValue;
notifyListeners();

navigationService.goBackToShell(index: shellCartIndex);
}

void _initProductImages() {
if (_productModel?.models?.isNotEmpty == true &&
_productModel.models[0] != null &&
_productModel.models[0].imageUrls?.isNotEmpty == true) {
images = [
CarouselImage(
tag: _productModel.id,
path: _productModel.models[0].imageUrls.first,
previewImage: _productModel.previewImage),
..._productModel.models[0].imageUrls
.skip(1)
.map((url) => CarouselImage(tag: _productModel.id, path: url))
.map((url) => CarouselImage(path: url))
.toList()
];
}
Expand Down Expand Up @@ -105,8 +120,9 @@ class ProductPageProviderModel extends ProviderModelBase {
ProductColorModel _covertToProductColorModel(ProductModel product) {
return ProductColorModel(
color: product?.color?.argb ?? 0,
title: product?.color?.title,
images: product.imageUrls
?.map((url) => CarouselImage(tag: _productModel?.id, path: url))
?.map((url) => CarouselImage(path: url))
?.toList());
}

Expand Down
41 changes: 20 additions & 21 deletions ecommers/lib/core/repositories/cart_repository.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import 'package:ecommers/core/common/index.dart';
import 'package:ecommers/core/models/cache_wrappers/order_model_wrapper.dart';
import 'package:ecommers/core/models/index.dart';
import 'package:ecommers/core/repositories/index.dart';
import 'package:ecommers/core/services/index.dart';

class CartRepository {
static const filterField = 'id';
class CartRepository extends RepositoryBase<OrderModelWrapper> {
static const filterFieldUserId = 'userId';
static const filterFieldOrderId = 'id';
CartRepository()
: super(
filterFieldForItem: filterFieldOrderId,
filterFieldForUser: filterFieldUserId,
repositoryKey: CacheDefines.orders,
);

Future<List<OrderModel>> getAllOrders() async {
return cacheDatabase.getAll(
membershipService.id.toString(), OrderModel.fromJson);
}

Future dropOrders() async {
await cacheDatabase.dropData(membershipService.id.toString());
}
final oederWrappers = await cacheDatabase.getByEqualsFilter(
repositoryKey,
OrderModelWrapper.fromJson,
{filterFieldUserId: membershipService.id});

Future editOrder(OrderModel order) async {
await cacheDatabase.updateByEqualsFilter(membershipService.id.toString(),
order.toJson(), {filterField: order.id});
return oederWrappers.map((e) => e.order).toList();
}

Future addOrder(OrderModel order) async {
await cacheDatabase.saveMap(
membershipService.id.toString(),
order.toJson(),
);
Future dropOrders() async {
await cacheDatabase.deleteDataByFilter(repositoryKey, {
filterFieldForUser: membershipService.id});
}

Future removeOrder(OrderModel order) async {
await cacheDatabase.deleteDataByFilter(
membershipService.id.toString(), {filterField: order.id});
}
}
1 change: 1 addition & 0 deletions ecommers/lib/core/repositories/index.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'cart_repository.dart';
export 'category_data_repository.dart';
export 'payment_method_repository.dart';
export 'repository_base.dart';
Loading