fixed issue add to cart

This commit is contained in:
2025-02-22 18:59:37 +05:30
parent 2c3e7e2992
commit 27c3a14646
17 changed files with 412 additions and 279 deletions

View File

@@ -992,7 +992,7 @@
"languageVersion": "3.4"
}
],
"generated": "2025-02-22T07:04:58.909640Z",
"generated": "2025-02-22T13:29:09.162780Z",
"generator": "pub",
"generatorVersion": "3.4.4",
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",

File diff suppressed because one or more lines are too long

BIN
assets/images/cart.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 MiB

BIN
assets/images/cartempty.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
assets/images/wishlist.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@@ -99,9 +99,18 @@ class MyRoutes {
animatedGoRoute(
path: PRODUCTDETAILS,
name: PRODUCTDETAILS,
pageBuilder: (context, state) {
final id = state.extra as String; // Get the extra object
return ProductDetails(id: id);
pageBuilder: (context, state)
{
// final id = state.extra as String; // Get the extra object
// return ProductDetails(id: id);
final args = state.extra as Map<String, dynamic>;
return ProductDetails(
id: args["id"],
quantity: args["quantity"],
price: args["price"],
);
},
),

View File

@@ -293,7 +293,6 @@ class AddtocartProvider extends ChangeNotifier {
};
}
try {
var result = await _homeRepo.paymentOrder(data);
return result.fold(
@@ -497,27 +496,31 @@ class AddtocartProvider extends ChangeNotifier {
);
},
(response) async {
print("kldfjghlkjfgkljh");
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,
// );
cartItems.add(productId);
iscardAdded = true;
notifyListeners(); // Update UI after adding to cart
notifyListeners();
},
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong"),
Fluttertoast.showToast(
msg: "Insufficient stock!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
),
textColor: Colors.white,
fontSize: 14.0,
);
context.showLoader(show: false);
await getItemCards(context);
// isLoadingCart = false;
// iscardAdded = true;
// isLoadings[productId] = false;
notifyListeners();
} finally {
isLoadingCart = false;
isLoadings[productId] = false;

View File

@@ -36,6 +36,7 @@ class ProductProvider extends ChangeNotifier {
bool hasMore = true;
bool iscroll = true;
Future<void> gettAllProduct(
BuildContext context, String id, bool status, String search) async {
if (isLoadingg || !hasMore) return;
@@ -132,12 +133,13 @@ class ProductProvider extends ChangeNotifier {
ProductDetailsData productDetails = ProductDetailsData();
bool isProductLoading = true;
Future<void> getProduuctDetails(BuildContext context, String id) async {
Future<void> getProduuctDetails(
BuildContext context, String id, int quantity, String price) async {
var data = {};
productDetails = ProductDetailsData();
isProductLoading = true;
quantitys = 1;
_totalPrice = 0.0;
quantitys = quantity;
_totalPrice = quantity * (double.parse(price));
notifyListeners();
var result = await _homeRepo.getProductDetails(data, context, id);
@@ -435,11 +437,13 @@ class ProductProvider extends ChangeNotifier {
},
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong"),
Fluttertoast.showToast(
msg: "Insufficient stock!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
backgroundColor: Colors.red,
),
textColor: Colors.white,
fontSize: 14.0,
);
} finally {
isLoadingCart = false;

View File

@@ -35,7 +35,7 @@ class ProfileProvider extends ChangeNotifier {
_uploadedUrl = uploadImage.data!.url.toString();
notifyListeners();
_showSnackBar(context, "Image uploaxded successfully!", Colors.green);
_showSnackBar(context, "Image uploaded successfully !", Colors.green);
return true;
},
);
@@ -123,7 +123,7 @@ class ProfileProvider extends ChangeNotifier {
allitem = response!;
_profile = response.img ?? '';
_name = response.firstName ?? "" + " " + response.lastName ?? '';
_name = response.firstName + " " + response.lastName;
_email = response.email ?? "";
APPSTRING.userName = response.firstName ?? "";

View File

@@ -299,7 +299,16 @@ class _BestDealScreenState extends State<BestDealScreen> {
return InkWell(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS,
extra: bestdealproduct.id);
extra: {
"id": bestdealproduct.id,
"quantity": 0,
"price": '0',
},
);
},
child: Container(
decoration: BoxDecoration(

View File

@@ -14,6 +14,7 @@ import 'package:grocery_app/src/logic/provider/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/bestdeal/bestdeal_screen.dart';
import 'package:grocery_app/src/ui/card_checkout/card_checkout_screen.dart';
import 'package:grocery_app/src/ui/data_notfound.dart';
import 'package:grocery_app/src/ui/widgets/custom_icon_button.dart';
import 'package:grocery_app/src/ui/widgets/elevated_button.dart';
@@ -112,7 +113,15 @@ class _MycartState extends State<Mycart> {
return InkWell(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS,
extra: bestdealproduct.id);
extra: {
"id":bestdealproduct.id,
"quantity": 0,
"price": "0",
},
);
},
child: Padding(
padding: const EdgeInsets.only(right: 5, bottom: 5, top: 5),
@@ -422,7 +431,12 @@ class _MycartState extends State<Mycart> {
} else if (provider.allitem == null ||
provider.allitem.items == null ||
provider.allitem.items!.isEmpty) {
return Center(child: Text('🛒 Your Front Shop Cart is empty'));
return DataNotFound(
imagePath: 'assets/images/cartempty.jpg',
message: "",
width: 250.w,
height: 200.h,
);
} else {
return ListView.separated(
shrinkWrap: true,
@@ -435,7 +449,19 @@ class _MycartState extends State<Mycart> {
itemBuilder: (context, index) {
var items = provider.allitem.items![index];
return Padding(
return InkWell(
onTap: ()
{
context.push(
MyRoutes.PRODUCTDETAILS,
extra: {
"id": items.product!.id,
"quantity": items.quantity,
"price": items.product!.discountPrice,
},
);
},
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10.w),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -448,7 +474,8 @@ class _MycartState extends State<Mycart> {
child: AppNetworkImage(
width: 60.w,
height: 70.h,
imageUrl: items.product!.productImages!.first.url ?? " ",
imageUrl:
items.product!.productImages!.first.url ?? " ",
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
),
@@ -463,12 +490,14 @@ class _MycartState extends State<Mycart> {
items.product!.name ?? "",
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
style:
context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
2.verticalSpace,
Text(
items.product!.unit ?? "",
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
style:
context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
Row(
children: [
@@ -504,7 +533,8 @@ class _MycartState extends State<Mycart> {
child: Text(
"${calculateDiscountPercentage(double.parse(items.product!.basePrice.toString()), double.parse(items.product!.discountPrice.toString()))}%off",
style: TextStyle(
color: Colors.lightGreen, fontSize: 12)),
color: Colors.lightGreen,
fontSize: 12)),
),
],
),
@@ -514,8 +544,8 @@ class _MycartState extends State<Mycart> {
showReturnPolicyBottomSheet(context);
},
child: Text("3 days Return & Exchange ",
style:
TextStyle(color: Colors.green, fontSize: 1)),
style: TextStyle(
color: Colors.green, fontSize: 1)),
),
],
),
@@ -625,6 +655,7 @@ class _MycartState extends State<Mycart> {
)
],
),
),
);
},
);
@@ -858,29 +889,6 @@ class _MycartState extends State<Mycart> {
),
),
),
// ElevatedButton(
// style: ElevatedButton.styleFrom(
// backgroundColor: APPCOLOR.lightGreen),
// onPressed: () {
// if (provider.isDeliverable) {
// _showAddressBottomSheet(context);
// } else {
// Fluttertoast.showToast(
// msg:
// "Delivery is not available for this pincode. Please try another pincode!",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: Colors.red,
// textColor: Colors.white,
// fontSize: 14.0,
// );
// }
// },
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [Text('Place Order', style: TextStyle(fontSize: 16))],
// ),
// ),
],
);
}

View File

@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
class DataNotFound extends StatelessWidget {
final String message;
final String imagePath;
final double width;
final double height;
const DataNotFound({
Key? key,
this.message = "No Data Available",
required this.imagePath,
this.width = 200,
this.height = 200,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
imagePath,
width: width,
height: height,
fit: BoxFit.contain,
),
const SizedBox(height: 20),
Text(
message,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
textAlign: TextAlign.center,
),
],
),
);
}
}

View File

@@ -161,7 +161,11 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Stack(
InkWell(
onTap: () {
_pickImage();
},
child: Stack(
alignment: Alignment.center,
children: [
CircleAvatar(
@@ -171,7 +175,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
? FileImage(_image!)
: (profile != null && profile!.isNotEmpty
? NetworkImage(profile!)
: const AssetImage("assets/default_profile.png")),
: const AssetImage(
"assets/default_profile.png")),
),
Positioned(
bottom: 0,
@@ -198,6 +203,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
)),
],
),
),
],
),
const SizedBox(

View File

@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/logic/provider/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/data_notfound.dart';
import 'package:grocery_app/src/ui/header.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
@@ -146,7 +148,13 @@ class _FavouriteScreenState extends State<FavouriteScreen>
return Expanded(
child: _buildSkeletonLoader()); // Show Skeleton while loading
} else if (provider.wishListItem.isEmpty) {
return Expanded(child: Center(child: Text('No products available')));
return Expanded(
child: DataNotFound(
imagePath: 'assets/images/wishlist.jpg',
message: "Your Wish list is empty. Please add some items",
width: 250.w,
height: 200.h,
));
} else {
return Expanded(
child: ListView.separated(
@@ -162,7 +170,15 @@ class _FavouriteScreenState extends State<FavouriteScreen>
return GestureDetector(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS, extra: productId);
context.push(MyRoutes.PRODUCTDETAILS,
// extra: productId
extra: {
"id":productId,
"quantity": 0,
"price": "0",
},
);
},
child: Container(
padding: EdgeInsets.all(8),

View File

@@ -1,11 +1,13 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/data_notfound.dart';
import 'package:grocery_app/utils/constants/assets_constant.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
@@ -121,8 +123,13 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
);
} else if (provider.products.isEmpty) {
return Padding(
padding: const EdgeInsets.only(left: 80),
child: Center(child: Text('No products available')),
padding: const EdgeInsets.only(left: 40),
child: DataNotFound(
imagePath: 'assets/images/cart.jpg',
message: "Product not abailable ",
width: 200.w,
height: 250.h,
),
);
} else {
return Expanded(
@@ -173,7 +180,15 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
return InkWell(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS,
extra: product.id);
// extra: product.id
extra: {
"id": product.id,
"quantity": 0,
"price": "0",
},
);
},
child: Container(
height: itemHeight,

View File

@@ -300,7 +300,16 @@ class _HomeScreenState extends State<HomeScreen> {
return InkWell(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS,
extra: bestdealproduct.id);
// extra: bestdealproduct.id
extra: {
"id":bestdealproduct.id,
"quantity": 0,
"price": "0",
},
);
},
child: Padding(
padding: const EdgeInsets.only(
@@ -679,7 +688,14 @@ class _HomeScreenState extends State<HomeScreen> {
return InkWell(
onTap: () {
context.push(MyRoutes.PRODUCTDETAILS,
extra: product.id);
// extra: product.id
extra: {
"id":product.id,
"quantity": 0,
"price": "0",
},
);
},
child: SizedBox(
child: Column(

View File

@@ -26,7 +26,14 @@ import 'package:shimmer/shimmer.dart';
class ProductDetails extends StatefulWidget {
String id;
ProductDetails({super.key, required this.id});
int quantity;
String price;
ProductDetails(
{super.key,
required this.id,
required this.quantity,
required this.price});
@override
State<ProductDetails> createState() => _ProductDetailsState();
@@ -41,7 +48,7 @@ class _ProductDetailsState extends State<ProductDetails> {
void initState() {
super.initState();
Provider.of<ProductProvider>(context, listen: false)
.getProduuctDetails(context, widget.id);
.getProduuctDetails(context, widget.id, widget.quantity, widget.price);
}
double value = 3.5;
@@ -979,7 +986,8 @@ class _ProductDetailsState extends State<ProductDetails> {
return InkWell(
onTap: () {
provider.getProduuctDetails(context, bestdealproduct.id);
provider.getProduuctDetails(
context, bestdealproduct.id, 0, "0");
},
child: Padding(
padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),