addres
This commit is contained in:
@@ -143,7 +143,8 @@ class AuthProvider extends ChangeNotifier {
|
||||
);
|
||||
return false; // Login failed
|
||||
},
|
||||
(response) {
|
||||
(response)
|
||||
{
|
||||
// Login success
|
||||
context.showLoader(show: false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/core/routes/routes.dart';
|
||||
import 'package:grocery_app/src/data/allProduct_model.dart';
|
||||
@@ -16,10 +17,12 @@ class ProductProvider extends ChangeNotifier {
|
||||
|
||||
List<Product> products = [];
|
||||
|
||||
Future<void> gettAllProduct(BuildContext context) async {
|
||||
Future<void> gettAllProduct(BuildContext context, String id) async {
|
||||
var data = {};
|
||||
|
||||
var result = await _homeRepo.getAllProduct(data, context);
|
||||
print("skdjhfgkf ${id}");
|
||||
|
||||
var result = await _homeRepo.getAllProduct(data, context, id);
|
||||
return result.fold(
|
||||
(error) {
|
||||
isLoadingg = false;
|
||||
@@ -63,7 +66,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
var result = await _homeRepo.getAllcategory(data, context);
|
||||
return result.fold(
|
||||
(error) {
|
||||
print("djhgfjdfhjg ${error}");
|
||||
print("djhgfjdfhjg ${error}");
|
||||
iscategroyloading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
@@ -152,4 +155,76 @@ class ProductProvider extends ChangeNotifier {
|
||||
_activeIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Mock API call
|
||||
Future<bool> addToWish(BuildContext context, String productId) async {
|
||||
//context.showLoader(show: true);
|
||||
|
||||
var data = {
|
||||
"productId": productId,
|
||||
};
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.addToWish(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
Fluttertoast.showToast(
|
||||
msg: "Wishlist updated successfully!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
|
||||
return true;
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> wishlist = {}; // To store product IDs in the wishlist
|
||||
|
||||
// Function to add/remove product from wishlist
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<void> toggleWishlist(BuildContext context, String productId) async {
|
||||
try {
|
||||
if (wishlist.contains(productId)) {
|
||||
wishlist.remove(productId);
|
||||
} else {
|
||||
// Call the API to add to wishlist
|
||||
var result = await addToWish(context, productId);
|
||||
|
||||
wishlist.add(productId); // Add the product ID to the wishlist
|
||||
}
|
||||
notifyListeners(); // Notify listeners to update the UI
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Something went wrong. Please try again."),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -89,20 +89,22 @@ class AuthRepo {
|
||||
// }
|
||||
// }
|
||||
|
||||
FutureResult<String> customerRegister(data) async {
|
||||
FutureResult<RegistrationResponse> customerRegister(data) async {
|
||||
try {
|
||||
var response = await _authServices.userRegister(data);
|
||||
|
||||
RegistrationResponse registrationResponse =
|
||||
registrationResponseFromJson(response.toString());
|
||||
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: registrationResponse.accessToken ?? "");
|
||||
if (response.statCode) {
|
||||
print("dsfklgjkfgbfgkfdgjkhkfdjg");
|
||||
}
|
||||
print("dsfklgjkfgbfgkfdgjkhkfdjg ${registrationResponse.accessToken}");
|
||||
// if (response.statCode) {
|
||||
// print("dsfklgjkfgbfgkfdgjkhkfdjg");
|
||||
// }
|
||||
|
||||
final String model = response.toString();
|
||||
return right(model);
|
||||
return right(registrationResponse);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
|
||||
@@ -14,9 +14,10 @@ class ProductRepo {
|
||||
|
||||
ProductRepo(this._productService);
|
||||
|
||||
FutureResult<AllProductModel> getAllProduct(data, BuildContext context) async {
|
||||
FutureResult<AllProductModel> getAllProduct(
|
||||
data, BuildContext context, id) async {
|
||||
try {
|
||||
var response = await _productService.getAllProduct(data);
|
||||
var response = await _productService.getAllProduct(data, id);
|
||||
|
||||
AllProductModel loginResponse =
|
||||
allProductModelFromJson(response.toString());
|
||||
@@ -30,7 +31,8 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<BestDealProduct> getBestDealProduct(data, BuildContext context) async {
|
||||
FutureResult<BestDealProduct> getBestDealProduct(
|
||||
data, BuildContext context) async {
|
||||
try {
|
||||
var response = await _productService.getBestDealProduct(data);
|
||||
|
||||
@@ -46,16 +48,48 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FutureResult<ProductCategory> getAllcategory(data, BuildContext context) async {
|
||||
FutureResult<ProductCategory> getAllcategory(
|
||||
data, BuildContext context) async {
|
||||
try {
|
||||
var response = await _productService.getAllcategory(data);
|
||||
|
||||
ProductCategory productCategory = productCategoryFromJson(response.toString());
|
||||
ProductCategory productCategory =
|
||||
productCategoryFromJson(response.toString());
|
||||
|
||||
// final String model = response.toString();
|
||||
// final String model = response.toString();
|
||||
|
||||
return right(productCategory);
|
||||
} on DioException catch (e) {
|
||||
print("djhgfjdfhjg ${e}");
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<String> addToWish(data) async
|
||||
{
|
||||
try {
|
||||
var response = await _productService.addToWish(data);
|
||||
|
||||
final String model = response.toString();
|
||||
|
||||
return right(model);
|
||||
} on DioException catch (e)
|
||||
{
|
||||
print("djhgfjdfhjg ${e}");
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<String> addToCart(data) async
|
||||
{
|
||||
try {
|
||||
var response = await _productService.addToCart(data);
|
||||
|
||||
final String model = response.toString();
|
||||
|
||||
return right(model);
|
||||
} on DioException catch (e)
|
||||
{
|
||||
print("djhgfjdfhjg ${e}");
|
||||
|
||||
@@ -17,31 +17,49 @@ class ProductService extends ApiService {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future getAllProduct(data) async
|
||||
{
|
||||
var response = await api.get(APIURL.getAllProduct, data: jsonEncode(data));
|
||||
Future getAllProduct(data, id) async {
|
||||
var response;
|
||||
|
||||
if (id.isEmpty) {
|
||||
response =
|
||||
await api.get(APIURL.getAllProduct, data: jsonEncode(data));
|
||||
}
|
||||
else{
|
||||
response = await api.get(APIURL.getAllProduct+ id, data: jsonEncode(data));
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Future getBestDealProduct(data) async
|
||||
{
|
||||
var response = await api.get(APIURL.getBestDealProduct, data: jsonEncode(data));
|
||||
Future getBestDealProduct(data) async {
|
||||
var response =
|
||||
await api.get(APIURL.getBestDealProduct, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future getAllcategory(data) async
|
||||
{
|
||||
Future getAllcategory(data) async {
|
||||
var response = await api.get(APIURL.getAllcategory, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future addToWish(data) async {
|
||||
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future addToCart(data) async {
|
||||
var response = await api.post(APIURL.addToCart, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future getBanners(data) async {
|
||||
var response = await api.get(APIURL.getBanners, data: jsonEncode(data));
|
||||
@@ -50,7 +68,8 @@ class ProductService extends ApiService {
|
||||
}
|
||||
|
||||
Future customerLogOut(data) async {
|
||||
var response = await api.post(APIURL.customerLogOut, data: jsonEncode(data));
|
||||
var response =
|
||||
await api.post(APIURL.customerLogOut, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user