updateProfile
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/data/address.dart';
|
||||
import 'package:grocery_app/src/data/all_cart_items.dart';
|
||||
import 'package:grocery_app/src/logic/repo/product_repo.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class AddtocartProvider extends ChangeNotifier {
|
||||
@@ -15,6 +18,7 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
String get pinCode => _pinCode;
|
||||
bool get isLoading => _isLoading;
|
||||
bool get isDeliverable => _isDeliverable;
|
||||
TextEditingController checkPinCode = TextEditingController();
|
||||
|
||||
Future<void> getCurrentLocation(BuildContext context) async {
|
||||
_isLoading = true;
|
||||
@@ -23,16 +27,6 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
try {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
_pinCode = "Location services disabled.";
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
LocationPermission permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
_pinCode = "Permission denied.";
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
|
||||
@@ -52,54 +46,58 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
|
||||
if (placemarks.isNotEmpty) {
|
||||
_pinCode = placemarks.first.postalCode ?? "Unknown";
|
||||
checkPinCode.text = _pinCode;
|
||||
print("Pincode found: $_pinCode");
|
||||
|
||||
// Now check if this pin code is deliverable
|
||||
await checkPin(context, _pinCode);
|
||||
} else {
|
||||
_pinCode = "Could not fetch pin code.";
|
||||
_pinCode = "unable to current pi code";
|
||||
print("Error: No placemarks found.");
|
||||
}
|
||||
} catch (e) {
|
||||
_pinCode = "Error: ${e.toString()}";
|
||||
_pinCode = "unable to current pi code";
|
||||
print("Error: ${e.toString()}");
|
||||
}
|
||||
|
||||
_pinCode = "unable to current pi code";
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
bool ischeckpin = false;
|
||||
Future<void> checkPin(BuildContext context, pin) async {
|
||||
ischeckpin = true;
|
||||
_pinCode = pin;
|
||||
notifyListeners();
|
||||
var data = {};
|
||||
try {
|
||||
var result = await _homeRepo.checkPin(data, pin);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
ischeckpin = false;
|
||||
_isDeliverable = false;
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
print("kdhfgkjfkghkfghkj ${response.isDeliverable!}");
|
||||
if (response.isDeliverable!) {
|
||||
_isDeliverable = true;
|
||||
}
|
||||
|
||||
ischeckpin = false;
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ischeckpin = false;
|
||||
_isDeliverable = false;
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Map<String, bool> isRemoveItem = {};
|
||||
Map<String, bool> isRemoveItem = {};
|
||||
|
||||
Future<void> deleteItem(BuildContext context, id) async {
|
||||
isRemoveItem[id] = true;
|
||||
@@ -109,18 +107,17 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
var result = await _homeRepo.deleteItem(data, id);
|
||||
return result.fold(
|
||||
(error) {
|
||||
|
||||
isRemoveItem[id] = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
getItemCards(context);
|
||||
isRemoveItem[id] = false;
|
||||
isRemoveItem[id] = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
isRemoveItem[id] = false;
|
||||
isRemoveItem[id] = false;
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -140,12 +137,10 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
print("dsjfgkjhkdfgdkjfhg");
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
print("dsjfgkjhkdjsfjkdhfsgfgdkjfhg");
|
||||
allitem = response!;
|
||||
isLoaddcartItem = false;
|
||||
notifyListeners();
|
||||
@@ -157,4 +152,165 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////// address/////////////////////////
|
||||
List<Datum> addresslist = [];
|
||||
|
||||
Future<void> getAddress(BuildContext context) async {
|
||||
var data = {};
|
||||
try {
|
||||
var result = await _homeRepo.getAddress(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
print("dsjfgkjhkdfgdkjfhg");
|
||||
|
||||
notifyListeners();
|
||||
},
|
||||
(response) {
|
||||
addresslist = response.data!;
|
||||
if (response.data!.isNotEmpty) {
|
||||
_selectedAddress = addresslist.last.id ?? "";
|
||||
} else {
|
||||
_selectedAddress = "";
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print("sfddsfdfff");
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
String _selectedAddress = "";
|
||||
|
||||
String get selectedAddress => _selectedAddress;
|
||||
|
||||
void selectAddress(String address) {
|
||||
_selectedAddress = address;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Set<String> cartItems = {};
|
||||
Map<String, bool> isLoadings = {};
|
||||
|
||||
bool isLoadingCart = false;
|
||||
bool iscardAdded = false;
|
||||
|
||||
Future<void> addToCart(
|
||||
BuildContext context, String productId, int quantity) async {
|
||||
context.showLoader(show: true);
|
||||
|
||||
isLoadingCart = true;
|
||||
isLoadings[productId] = true;
|
||||
notifyListeners();
|
||||
|
||||
var data = {"productId": productId, "quantity": quantity};
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.addToCart(data);
|
||||
context.showLoader(
|
||||
show: false,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
},
|
||||
(response) async {
|
||||
await getItemCards(context);
|
||||
cartItems.add(productId); // Add product to cart
|
||||
// Fluttertoast.showToast(
|
||||
// msg: "Added to cart successfully!",
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.green,
|
||||
// textColor: Colors.white,
|
||||
// fontSize: 14.0,
|
||||
// );
|
||||
iscardAdded = true;
|
||||
notifyListeners(); // Update UI after adding to cart
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Something went wrong"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
isLoadingCart = false;
|
||||
isLoadings[productId] = false;
|
||||
notifyListeners(); // Ensure UI updates after operation
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> decreaseCartQuantity(
|
||||
BuildContext context, String itemId, int quantity) async {
|
||||
context.showLoader(show: true);
|
||||
|
||||
isLoadingCart = true;
|
||||
|
||||
notifyListeners();
|
||||
|
||||
// var data = {"productId": productId, "quantity": quantity};
|
||||
|
||||
final Map<String, dynamic> cartData = {
|
||||
"items": [
|
||||
{"itemId": itemId, "quantity": quantity}
|
||||
]
|
||||
};
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.decreaseQuantity(cartData);
|
||||
context.showLoader(
|
||||
show: false,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
},
|
||||
(response) async {
|
||||
await getItemCards(context);
|
||||
|
||||
// Fluttertoast.showToast(
|
||||
// msg: "Added to cart successfully!",
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.green,
|
||||
// textColor: Colors.white,
|
||||
// fontSize: 14.0,
|
||||
// );
|
||||
iscardAdded = true;
|
||||
notifyListeners(); // Update UI after adding to cart
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Something went wrong"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
isLoadingCart = false;
|
||||
|
||||
notifyListeners(); // Ensure UI updates after operation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
74
lib/src/logic/provider/address_provider.dart
Normal file
74
lib/src/logic/provider/address_provider.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/logic/repo/product_repo.dart';
|
||||
|
||||
class AddressProvider extends ChangeNotifier {
|
||||
bool ischeckpin = false;
|
||||
|
||||
Future<bool> checkPin(BuildContext context, pin) async {
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
ischeckpin = true;
|
||||
notifyListeners();
|
||||
var data = {};
|
||||
try {
|
||||
var result = await _homeRepo.checkPin(data, pin);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
ischeckpin = false;
|
||||
ischeckpin = false;
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
ischeckpin = false;
|
||||
notifyListeners();
|
||||
return true;
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ischeckpin = false;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> addAddress(BuildContext context, name, pincode, phone,
|
||||
alternatePhoneNumber, address, landmark, addresstype) async {
|
||||
ischeckpin = false;
|
||||
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
|
||||
notifyListeners();
|
||||
var data = {
|
||||
"name": name,
|
||||
"pincode": pincode,
|
||||
"phoneNumber": "+91$phone",
|
||||
"alternatePhoneNumber": "+91$alternatePhoneNumber",
|
||||
"addressLine": address,
|
||||
"landmark": landmark,
|
||||
"addressType": addresstype,
|
||||
"isDefault": false,
|
||||
"additionalInstructions": "Please ring doorbell twice"
|
||||
};
|
||||
try {
|
||||
var result = await _homeRepo.addAddress(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
ischeckpin = false;
|
||||
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
ischeckpin = false;
|
||||
notifyListeners();
|
||||
return true;
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ischeckpin = false;
|
||||
notifyListeners();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/data/user_profile.dart';
|
||||
import 'package:grocery_app/src/logic/repo/product_repo.dart';
|
||||
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
|
||||
|
||||
class BottomNavProvider with ChangeNotifier {
|
||||
int _currentIndex = 0;
|
||||
@@ -7,10 +11,58 @@ class BottomNavProvider with ChangeNotifier {
|
||||
int get currentIndex => _currentIndex;
|
||||
PageController get pageController => _pageController;
|
||||
|
||||
void setIndex(int index)
|
||||
{
|
||||
void setIndex(int index) {
|
||||
_currentIndex = index;
|
||||
_pageController.jumpToPage(index);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
UserProfile allitem = UserProfile();
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
bool isLoading = true;
|
||||
|
||||
Future<void> getProfile(BuildContext context) async {
|
||||
print("kjdkjghdfjglhjdfhgldflghjkldfjgh");
|
||||
isLoading = true;
|
||||
notifyListeners();
|
||||
var data = {};
|
||||
try {
|
||||
var result = await _homeRepo.getProfile(data);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response) async {
|
||||
print("kjdshgkjhdfkjg ${response.firstName}");
|
||||
|
||||
await SharedPrefUtils.saveUser(user: response);
|
||||
allitem = response!;
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> refreshToken(BuildContext context) async {
|
||||
var data = {"refresh_token": "${await SharedPrefUtils.getRefreshToken()}"};
|
||||
|
||||
|
||||
var result = await _homeRepo.refreshToken(data, context);
|
||||
return result.fold(
|
||||
(error) {
|
||||
|
||||
return true;
|
||||
},
|
||||
(response) {
|
||||
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ class ProductProvider extends ChangeNotifier {
|
||||
var data = {};
|
||||
productDetails = ProductDetailsData();
|
||||
isProductLoading = true;
|
||||
quantitys = 1;
|
||||
_totalPrice = 0.0;
|
||||
notifyListeners();
|
||||
|
||||
var result = await _homeRepo.getProductDetails(data, context, id);
|
||||
@@ -186,8 +188,6 @@ class ProductProvider extends ChangeNotifier {
|
||||
|
||||
// Mock API call
|
||||
Future<bool> addToWish(BuildContext context, String productId) async {
|
||||
print("jsdkjfhkdfkg ${productId}");
|
||||
|
||||
var data = {
|
||||
"productId": productId,
|
||||
};
|
||||
@@ -206,6 +206,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
iswishloading = false;
|
||||
Fluttertoast.showToast(
|
||||
msg: "Wishlist updated successfully!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
@@ -223,18 +224,24 @@ class ProductProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> wishlist = {}; // To store product IDs in the wishlist
|
||||
Set<String> wishlist = {};
|
||||
|
||||
bool iswishloading = false;
|
||||
|
||||
Future<void> toggleWishlist(BuildContext context, String productId) async {
|
||||
iswishloading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
if (wishlist.contains(productId)) {
|
||||
wishlist.remove(productId);
|
||||
iswishloading = false;
|
||||
} else {
|
||||
var result = await addToWish(context, productId);
|
||||
|
||||
wishlist.add(productId); // Add the product ID to the wishlist
|
||||
wishlist.add(productId);
|
||||
}
|
||||
notifyListeners(); // Notify listeners to update the UI
|
||||
iswishloading = false;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
@@ -297,13 +304,16 @@ class ProductProvider extends ChangeNotifier {
|
||||
Set<String> cartItems = {};
|
||||
Map<String, bool> isLoading = {};
|
||||
|
||||
Future<void> addToCart(BuildContext context, String productId) async {
|
||||
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
|
||||
bool isLoadingCart=false;
|
||||
bool iscardAdded=false;
|
||||
|
||||
Future<void> addToCart(BuildContext context, String productId,int quantity) async {
|
||||
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
|
||||
isLoadingCart=true;
|
||||
isLoading[productId] = true;
|
||||
notifyListeners(); // Notify UI to show loading indicator
|
||||
|
||||
var data = {"productId": productId, "quantity": 1};
|
||||
var data = {"productId": productId, "quantity": quantity};
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.addToCart(data);
|
||||
@@ -327,6 +337,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
iscardAdded=true;
|
||||
notifyListeners(); // Update UI after adding to cart
|
||||
},
|
||||
);
|
||||
@@ -338,19 +349,20 @@ class ProductProvider extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
isLoadingCart=false;
|
||||
isLoading[productId] = false;
|
||||
notifyListeners(); // Ensure UI updates after operation
|
||||
}
|
||||
}
|
||||
|
||||
List<BestDeal> countList = [];
|
||||
String lastImageurl = '';
|
||||
|
||||
Future<void> addToWithCart(
|
||||
BuildContext context, String productId, BestDeal bestdealproduct) async {
|
||||
//if (cartItems.contains(productId)) return; // Prevent duplicate additions
|
||||
|
||||
Future<void> addToWithCart(BuildContext context, String productId,
|
||||
BestDeal bestdealproduct, url) async {
|
||||
|
||||
isLoading[productId] = true;
|
||||
notifyListeners(); // Notify UI to show loading indicator
|
||||
notifyListeners();
|
||||
|
||||
var data = {"productId": productId, "quantity": 1};
|
||||
|
||||
@@ -368,6 +380,7 @@ class ProductProvider extends ChangeNotifier {
|
||||
},
|
||||
(response) {
|
||||
countList.add(bestdealproduct);
|
||||
lastImageurl = url;
|
||||
cartItems.add(productId); // Add product to cart
|
||||
Fluttertoast.showToast(
|
||||
msg: "Added to cart successfully!",
|
||||
@@ -393,6 +406,63 @@ class ProductProvider extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<ProductDatum> productDatum = [];
|
||||
String productDatumlastImageurl = '';
|
||||
|
||||
Future<void> addToCartWithWishlist(BuildContext context, String productId,ProductDatum productdataum,
|
||||
url) async {
|
||||
|
||||
isLoading[productId] = true;
|
||||
notifyListeners();
|
||||
|
||||
var data = {"productId": productId, "quantity": 1};
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.addToCart(data);
|
||||
|
||||
result.fold(
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
},
|
||||
(response) {
|
||||
productDatum.add(productdataum);
|
||||
productDatumlastImageurl = url;
|
||||
cartItems.add(productId); // Add product to cart
|
||||
Fluttertoast.showToast(
|
||||
msg: "Added to cart successfully!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.green,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
notifyListeners(); // Update UI after adding to cart
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Something went wrong"),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
} finally {
|
||||
isLoading[productId] = false;
|
||||
notifyListeners(); // Ensure UI updates after operation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool isWishListItemLoadingg = true;
|
||||
|
||||
List<WishListItem> wishListItem = [];
|
||||
@@ -427,30 +497,69 @@ class ProductProvider extends ChangeNotifier {
|
||||
}
|
||||
////////////////////////////// product increase ////////////////////////////////////
|
||||
|
||||
int _quantity = 1;
|
||||
int quantitys = 1;
|
||||
double _unitPrice = 0.0;
|
||||
double _totalPrice = 0.0;
|
||||
|
||||
int get quantity => _quantity;
|
||||
int get quantity => quantitys;
|
||||
double get totalPrice => _totalPrice;
|
||||
|
||||
void setProductPrice(double price) {
|
||||
_unitPrice = price;
|
||||
_totalPrice = _unitPrice * _quantity;
|
||||
_totalPrice = _unitPrice * quantitys;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
int productQuantity = 0;
|
||||
|
||||
// void increaseQuantity()
|
||||
// {
|
||||
// if(quantity<10)
|
||||
// if (_quantity < 10)
|
||||
// {
|
||||
// // Limit to 10
|
||||
// _quantity++;
|
||||
// _totalPrice = _unitPrice * _quantity;
|
||||
// notifyListeners();
|
||||
// }
|
||||
// {
|
||||
// Fluttertoast.showToast(
|
||||
// msg: "Sorry cart successfully!",
|
||||
// toastLength: Toast.LENGTH_SHORT,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.green,
|
||||
// textColor: Colors.white,
|
||||
// fontSize: 14.0,
|
||||
// );
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
void increaseQuantity() {
|
||||
print("kjfgkhkdfhgkjdhfg");
|
||||
_quantity++;
|
||||
_totalPrice = _unitPrice * _quantity;
|
||||
notifyListeners();
|
||||
int maxAllowed = productQuantity >= 100
|
||||
? 10
|
||||
: productQuantity; // Max limit based on stock
|
||||
|
||||
if (quantitys < maxAllowed) {
|
||||
quantitys++;
|
||||
_totalPrice = _unitPrice * quantitys;
|
||||
notifyListeners();
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: "Sorry, you can only add up to $maxAllowed items!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
backgroundColor: Colors.red,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void decreaseQuantity() {
|
||||
if (_quantity > 1) {
|
||||
_quantity--;
|
||||
_totalPrice = _unitPrice * _quantity;
|
||||
if (quantitys > 1) {
|
||||
quantitys--;
|
||||
_totalPrice = _unitPrice * quantitys;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
94
lib/src/logic/provider/profile_provider.dart
Normal file
94
lib/src/logic/provider/profile_provider.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/src/core/network_services/service_locator.dart';
|
||||
import 'package:grocery_app/src/core/utils/snack_bar.dart';
|
||||
import 'package:grocery_app/src/data/user_profile.dart';
|
||||
import 'package:grocery_app/src/logic/repo/auth_repo.dart';
|
||||
import 'package:grocery_app/src/logic/repo/product_repo.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
|
||||
class ProfileProvider extends ChangeNotifier {
|
||||
bool _isImageLoading = false;
|
||||
bool get isImageLoading => _isImageLoading;
|
||||
|
||||
String _uploadedUrl = '';
|
||||
|
||||
final _productRepo = getIt<ProductRepo>();
|
||||
|
||||
Future<bool> uploadImage(BuildContext context, File? _selectedImage) async {
|
||||
context.showLoader(show: true);
|
||||
_isImageLoading = false;
|
||||
final result = await _productRepo.uploadImage(_selectedImage!);
|
||||
context.showLoader(show: false);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
_showSnackBar(context, error.message, Colors.red);
|
||||
return false;
|
||||
},
|
||||
(uploadImage) {
|
||||
_isImageLoading = true;
|
||||
_uploadedUrl = uploadImage.data!.url.toString();
|
||||
notifyListeners();
|
||||
|
||||
_showSnackBar(context, "Image uploaxded successfully!", Colors.green);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showSnackBar(BuildContext context, String message, Color color) {
|
||||
showTopSnackBar(context, message, color);
|
||||
}
|
||||
|
||||
Future<bool> createStore(
|
||||
BuildContext context, String firstName, String lastName) async {
|
||||
context.showLoader(show: true);
|
||||
|
||||
var data = {
|
||||
"firstName": firstName,
|
||||
"lastName": lastName,
|
||||
"img": _uploadedUrl
|
||||
};
|
||||
|
||||
try {
|
||||
var result = await _productRepo.updateProfile(data);
|
||||
|
||||
context.showLoader(show: false);
|
||||
|
||||
return result.fold(
|
||||
(error) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error.message),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
},
|
||||
(response) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Profile updated"),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
return true;
|
||||
},
|
||||
);
|
||||
} catch (e)
|
||||
{
|
||||
context.showLoader(show: false);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text("Something went wrong. Please try again."),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:grocery_app/src/core/utils/response_type_def.dart';
|
||||
import 'package:grocery_app/src/data/OTPResponseModel.dart';
|
||||
import 'package:grocery_app/src/data/login_response.dart';
|
||||
import 'package:grocery_app/src/data/registration_response.dart';
|
||||
import 'package:grocery_app/src/data/user_profile.dart';
|
||||
import 'package:grocery_app/src/data/vendor_otpModel.dart';
|
||||
import 'package:grocery_app/src/logic/services/auth_service_locator.dart';
|
||||
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
|
||||
@@ -20,7 +21,6 @@ class AuthRepo {
|
||||
try {
|
||||
var response = await _authServices.sendOtp(data);
|
||||
final String model = response.toString();
|
||||
|
||||
|
||||
return right(model);
|
||||
} on DioException catch (e) {
|
||||
@@ -40,10 +40,10 @@ class AuthRepo {
|
||||
if (vendorOtpModel.data != null) {
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: vendorOtpModel.data!.accessToken ?? "");
|
||||
await SharedPrefUtils.setRefreshToken(
|
||||
refresh_token: vendorOtpModel.data!.refreshToken ?? "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
return right(vendorOtpModel);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
@@ -51,16 +51,17 @@ class AuthRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<LoginResponse> loginOtp(data) async {
|
||||
FutureResult<LoginResponse> loginOtp(data) async {
|
||||
try {
|
||||
var response = await _authServices.loginOtp(data);
|
||||
|
||||
LoginResponse loginResponse = loginResponseFromJson(response.toString());
|
||||
|
||||
if (loginResponse.accessToken != null)
|
||||
{
|
||||
if (loginResponse.accessToken != null) {
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: loginResponse.accessToken ?? "");
|
||||
await SharedPrefUtils.setRefreshToken(
|
||||
refresh_token: loginResponse.refreshToken ?? "");
|
||||
}
|
||||
|
||||
// final String model = response.toString();
|
||||
@@ -119,12 +120,9 @@ class AuthRepo {
|
||||
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: registrationResponse.accessToken ?? "");
|
||||
print("dsfklgjkfgbfgkfdgjkhkfdjg ${registrationResponse.accessToken}");
|
||||
// if (response.statCode) {
|
||||
// print("dsfklgjkfgbfgkfdgjkhkfdjg");
|
||||
// }
|
||||
|
||||
final String model = response.toString();
|
||||
await SharedPrefUtils.setRefreshToken(
|
||||
refresh_token: registrationResponse.refreshToken ?? "");
|
||||
final String model = response.toString();
|
||||
return right(registrationResponse);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:grocery_app/src/core/routes/routes.dart';
|
||||
import 'package:grocery_app/src/core/utils/custom_dio_exception.dart';
|
||||
import 'package:grocery_app/src/core/utils/response_type_def.dart';
|
||||
import 'package:grocery_app/src/data/address.dart';
|
||||
import 'package:grocery_app/src/data/allProduct_model.dart';
|
||||
import 'package:grocery_app/src/data/all_cart_items.dart';
|
||||
import 'package:grocery_app/src/data/banners.dart';
|
||||
import 'package:grocery_app/src/data/best_dealProduct.dart';
|
||||
import 'package:grocery_app/src/data/check_pin_response.dart';
|
||||
import 'package:grocery_app/src/data/login_response.dart';
|
||||
import 'package:grocery_app/src/data/product_category.dart';
|
||||
import 'package:grocery_app/src/data/product_details.dart';
|
||||
import 'package:grocery_app/src/data/upload_image.dart';
|
||||
import 'package:grocery_app/src/data/user_profile.dart';
|
||||
import 'package:grocery_app/src/data/wish_list_model.dart';
|
||||
import 'package:grocery_app/src/logic/services/home_locator.dart';
|
||||
import 'package:grocery_app/src/ui/productdetails/product_details.dart';
|
||||
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
|
||||
class ProductRepo {
|
||||
final ProductService _productService;
|
||||
@@ -36,12 +45,13 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<ProductDetailsData> getProductDetails(
|
||||
FutureResult<ProductDetailsData> getProductDetails(
|
||||
data, BuildContext context, id) async {
|
||||
try {
|
||||
var response = await _productService.getProductDetails(data, id);
|
||||
|
||||
ProductDetailsData loginResponse = productDetailsdataFromJson(response.toString());
|
||||
ProductDetailsData loginResponse =
|
||||
productDetailsdataFromJson(response.toString());
|
||||
|
||||
final String model = response.toString();
|
||||
|
||||
@@ -52,8 +62,6 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
FutureResult<BestDealProduct> getBestDealProduct(
|
||||
data, BuildContext context) async {
|
||||
try {
|
||||
@@ -112,8 +120,19 @@ class ProductRepo {
|
||||
var response = await _productService.getItemCards(data);
|
||||
|
||||
AllCartItems allCartItems = allCartItemsFromJson(response.toString());
|
||||
return right(allCartItems);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
print("jdfgjkdf${allCartItems}");
|
||||
FutureResult<AddressResponse> getAddress(data) async {
|
||||
try {
|
||||
var response = await _productService.getAddress(data);
|
||||
|
||||
AddressResponse allCartItems =
|
||||
addressResponseFromJson(response.toString());
|
||||
|
||||
return right(allCartItems);
|
||||
} on DioException catch (e) {
|
||||
@@ -123,6 +142,47 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<UserProfile> getProfile(data) async {
|
||||
try {
|
||||
var response = await _productService.getProfile(data);
|
||||
|
||||
print("kdjfgkljfdkjlghflkgjh ${response}");
|
||||
UserProfile userProfile = userProfileFromJson(response.toString());
|
||||
print("kdjfgkljfdkjlghflkgjhrerrrerr ${userProfile.createdAt}");
|
||||
return right(userProfile);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
FutureResult<String> updateProfile(data) async {
|
||||
try {
|
||||
var response = await _productService.updateProfile(data);
|
||||
|
||||
print("kdjfgkljfdkjlghflkgjh ${response}");
|
||||
final String model = response.toString();
|
||||
return right(model);
|
||||
} on DioException catch (e) {
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
FutureResult<UploadImage> uploadImage(File imageFile)
|
||||
async {
|
||||
try {
|
||||
final response = await _productService.uploadImage(imageFile);
|
||||
UploadImage upload=uploadImageFromJson(response.toString());
|
||||
return right(upload);
|
||||
} on DioException catch (e) {
|
||||
final error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
FutureResult<CheckPinResponse> checkPin(data, pin) async {
|
||||
try {
|
||||
var response = await _productService.checkPin(data, pin);
|
||||
@@ -148,6 +208,20 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<String> addAddress(data) async {
|
||||
try {
|
||||
var response = await _productService.addAddress(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> addToWish(data) async {
|
||||
try {
|
||||
var response = await _productService.addToWish(data);
|
||||
@@ -175,6 +249,22 @@ class ProductRepo {
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
FutureResult<String> decreaseQuantity(data) async {
|
||||
try {
|
||||
var response = await _productService.decreaseQuantity(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<WishListModel> gettAllWishList(data) async {
|
||||
try {
|
||||
@@ -221,6 +311,32 @@ class ProductRepo {
|
||||
}
|
||||
}
|
||||
|
||||
FutureResult<String> refreshToken(data, BuildContext context) async {
|
||||
try {
|
||||
var response = await _productService.refresh_token(data);
|
||||
LoginResponse loginResponse = loginResponseFromJson(response.toString());
|
||||
|
||||
if (loginResponse.accessToken != null)
|
||||
{
|
||||
|
||||
await SharedPrefUtils.setToken(
|
||||
authToken: loginResponse.accessToken ?? "");
|
||||
await SharedPrefUtils.setRefreshToken(
|
||||
refresh_token: loginResponse.refreshToken ?? "");
|
||||
}
|
||||
|
||||
final String model = response.toString();
|
||||
|
||||
return right(model);
|
||||
} on DioException catch (e)
|
||||
{
|
||||
|
||||
|
||||
var error = CustomDioExceptions.handleError(e);
|
||||
return left(error);
|
||||
}
|
||||
}
|
||||
|
||||
// FutureResult<VendorModel> getMe(data) async {
|
||||
// try {
|
||||
// var response = await _homeService.getMe(data);
|
||||
|
||||
@@ -1,82 +1,58 @@
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:grocery_app/src/core/constant/api.dart';
|
||||
import 'package:grocery_app/src/core/network_services/api_services.dart';
|
||||
|
||||
|
||||
|
||||
class AuthServices extends ApiService {
|
||||
/// Login
|
||||
Future sendOtp(data) async
|
||||
{
|
||||
Future sendOtp(data) async {
|
||||
var response = await api.post(APIURL.sendOtp, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future verifyOtp(data) async {
|
||||
Future verifyOtp(data) async {
|
||||
var response = await api.post(APIURL.verifyOtp, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
Future loginOtp(data) async {
|
||||
|
||||
Future loginOtp(data) async {
|
||||
var response = await api.post(APIURL.loginOtp, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future login(data) async
|
||||
{
|
||||
Future login(data) async {
|
||||
var response = await api.post(APIURL.login, data: jsonEncode(data));
|
||||
//response.statusCode
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future userRegister(data) async
|
||||
{
|
||||
var response = await api.post(APIURL.customerRegister, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Future forgetPassword(data) async
|
||||
{
|
||||
var response = await api.post(APIURL.forgetPassword, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
Future verifyForgetPassword(data) async
|
||||
{
|
||||
var response = await api.post(APIURL.verifyForgetPassword, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future reset_password(data) async
|
||||
{
|
||||
var response = await api.post(APIURL.reset_password, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future userRegister(data) async {
|
||||
var response =
|
||||
await api.post(APIURL.customerRegister, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future forgetPassword(data) async {
|
||||
var response =
|
||||
await api.post(APIURL.forgetPassword, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
Future verifyForgetPassword(data) async {
|
||||
var response =
|
||||
await api.post(APIURL.verifyForgetPassword, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future reset_password(data) async {
|
||||
var response =
|
||||
await api.post(APIURL.reset_password, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
/// Login
|
||||
// Future profileUpdate(data) async {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:grocery_app/src/core/constant/api.dart';
|
||||
import 'package:grocery_app/src/core/network_services/api_services.dart';
|
||||
|
||||
@@ -76,7 +78,39 @@ class ProductService extends ApiService {
|
||||
await api.delete(APIURL.deleteItem + id, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
Future addAddress(data) async {
|
||||
var response = await api.post(APIURL.addAddress, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future getProfile(data) async {
|
||||
var response = await api.get(APIURL.getprofile, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
Future updateProfile(data) async {
|
||||
var response = await api.patch(APIURL.updateProfile, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Future<Response> uploadImage(File imageFile,
|
||||
{Map<String, dynamic>? additionalFields}) async {
|
||||
const String url = APIURL.uploadImage;
|
||||
return await api.uploadImage(
|
||||
url,
|
||||
imageFile,
|
||||
additionalFields: additionalFields,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Future getAddress
|
||||
(data) async {
|
||||
var response =
|
||||
await api.get(APIURL.userAddress, data: jsonEncode(data));
|
||||
return response;
|
||||
}
|
||||
Future addToWish(data) async {
|
||||
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
|
||||
|
||||
@@ -89,6 +123,12 @@ class ProductService extends ApiService {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future decreaseQuantity(data) async {
|
||||
var response = await api.patch(APIURL.addToCart, data: jsonEncode(data));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future gettAllWishList(data) async {
|
||||
var response =
|
||||
await api.get(APIURL.gettAllWishList, data: jsonEncode(data));
|
||||
|
||||
Reference in New Issue
Block a user