This commit is contained in:
bestonemitRam
2025-01-29 00:59:14 +05:30
parent 3121e0ee36
commit 5c69ac3322
20 changed files with 1638 additions and 649 deletions

View File

@@ -12,16 +12,14 @@ class APIURL {
static const String getAllcategory = "${BASE_URL}categories";
static const String addToWish = "${BASE_URL}carts/wishlist/items";
static const String addToCart = "${BASE_URL}carts/items";
static const String gettAllWishList = "${BASE_URL}carts/wishlist";
static const String updateStore = "${BASE_URL}stores/";
static const String forgetPassword = "${BASE_URL}auth/forgot-password/vendor";
static const String verifyForgetPassword =
"${BASE_URL}auth/forgot-password-verify-otp/vendor";
static const String reset_password = "${BASE_URL}auth/reset-password/vendor";
static const String getProduct = "${BASE_URL}products";
static const String getCategoryByLevel = "${BASE_URL}categories/by-level/1";
static const String getMe = "${BASE_URL}auth/me";

View File

@@ -62,6 +62,10 @@ class Product {
List<dynamic>? zones;
List<ProductReview>? productReview;
Product({
this.id,
this.name,

View File

@@ -0,0 +1,249 @@
// To parse this JSON data, do
//
// final wishListModel = wishListModelFromJson(jsondynamic);
import 'dart:convert';
WishListModel wishListModelFromJson(dynamic str) => WishListModel.fromJson(json.decode(str));
dynamic wishListModelToJson(WishListModel data) => json.encode(data.toJson());
class WishListModel {
dynamic id;
dynamic userId;
DateTime? createdAt;
DateTime? updatedAt;
List<WishListItem>? items;
dynamic? totalItems;
WishListModel({
this.id,
this.userId,
this.createdAt,
this.updatedAt,
this.items,
this.totalItems,
});
factory WishListModel.fromJson(Map<dynamic, dynamic> json) => WishListModel(
id: json["id"],
userId: json["userId"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
items: List<WishListItem>.from(json["items"].map((x) => WishListItem.fromJson(x))),
totalItems: json["totalItems"],
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"userId": userId,
"createdAt": createdAt,
"updatedAt": updatedAt,
"items": List<dynamic>.from(items!.map((x) => x.toJson())),
"totalItems": totalItems,
};
}
class WishListItem {
dynamic id;
dynamic wishlistId;
dynamic productId;
dynamic storeId;
DateTime? createdAt;
DateTime? updatedAt;
ProductDatum? product;
Store? store;
WishListItem({
this.id,
this.wishlistId,
this.productId,
this.storeId,
this.createdAt,
this.updatedAt,
this.product,
this.store,
});
factory WishListItem.fromJson(Map<dynamic, dynamic> json) => WishListItem(
id: json["id"],
wishlistId: json["wishlistId"],
productId: json["productId"],
storeId: json["storeId"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
product: ProductDatum.fromJson(json["product"]),
store: Store.fromJson(json["store"]),
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"wishlistId": wishlistId,
"productId": productId,
"storeId": storeId,
"createdAt": createdAt,
"updatedAt": updatedAt,
"product": product!.toJson(),
"store": store!.toJson(),
};
}
class ProductDatum {
dynamic id;
dynamic name;
dynamic description;
dynamic additionalInfo;
dynamic brand;
dynamic basePrice;
dynamic discountPrice;
dynamic stock;
dynamic quantity;
dynamic unit;
dynamic slug;
dynamic rating;
bool? isInStock;
bool? isActive;
bool? isInWishlist;
DateTime? createdAt;
DateTime? updatedAt;
dynamic storeId;
dynamic categoryId;
dynamic productTypeId;
dynamic timeSlotId;
ProductDatum({
this.id,
this.name,
this.description,
this.additionalInfo,
this.brand,
this.basePrice,
this.discountPrice,
this.stock,
this.quantity,
this.unit,
this.slug,
this.rating,
this.isInStock,
this.isActive,
this.isInWishlist,
this.createdAt,
this.updatedAt,
this.storeId,
this.categoryId,
this.productTypeId,
this.timeSlotId,
});
factory ProductDatum.fromJson(Map<dynamic, dynamic> json) => ProductDatum(
id: json["id"],
name: json["name"],
description: json["description"],
additionalInfo: json["additionalInfo"],
brand: json["brand"],
basePrice: json["basePrice"],
discountPrice: json["discountPrice"],
stock: json["stock"],
quantity: json["quantity"],
unit: json["unit"],
slug: json["slug"],
rating: json["rating"],
isInStock: json["isInStock"],
isActive: json["isActive"],
isInWishlist: json["isInWishlist"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
storeId: json["storeId"],
categoryId: json["categoryId"],
productTypeId: json["productTypeId"],
timeSlotId: json["timeSlotId"],
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"additionalInfo": additionalInfo,
"brand": brand,
"basePrice": basePrice,
"discountPrice": discountPrice,
"stock": stock,
"quantity": quantity,
"unit": unit,
"slug": slug,
"rating": rating,
"isInStock": isInStock,
"isActive": isActive,
"isInWishlist": isInWishlist,
"createdAt": createdAt,
"updatedAt": updatedAt,
"storeId": storeId,
"categoryId": categoryId,
"productTypeId": productTypeId,
"timeSlotId": timeSlotId,
};
}
class Store {
dynamic id;
dynamic storeName;
dynamic storeDescription;
dynamic officialPhoneNumber;
dynamic storeAddress;
dynamic gstNumber;
dynamic gumastaNumber;
dynamic storePicture;
DateTime? createdAt;
DateTime? updatedAt;
dynamic vendorId;
bool? isActive;
dynamic couponId;
Store({
this.id,
this.storeName,
this.storeDescription,
this.officialPhoneNumber,
this.storeAddress,
this.gstNumber,
this.gumastaNumber,
this.storePicture,
this.createdAt,
this.updatedAt,
this.vendorId,
this.isActive,
this.couponId,
});
factory Store.fromJson(Map<dynamic, dynamic> json) => Store(
id: json["id"],
storeName: json["storeName"],
storeDescription: json["storeDescription"],
officialPhoneNumber: json["officialPhoneNumber"],
storeAddress: json["storeAddress"],
gstNumber: json["gstNumber"],
gumastaNumber: json["gumastaNumber"],
storePicture: json["storePicture"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
vendorId: json["vendorId"],
isActive: json["isActive"],
couponId: json["couponId"],
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"storeName": storeName,
"storeDescription": storeDescription,
"officialPhoneNumber": officialPhoneNumber,
"storeAddress": storeAddress,
"gstNumber": gstNumber,
"gumastaNumber": gumastaNumber,
"storePicture": storePicture,
"createdAt": createdAt,
"updatedAt": updatedAt,
"vendorId": vendorId,
"isActive": isActive,
"couponId": couponId,
};
}

View File

@@ -6,6 +6,7 @@ import 'package:grocery_app/src/data/allProduct_model.dart';
import 'package:grocery_app/src/data/banners.dart';
import 'package:grocery_app/src/data/best_dealProduct.dart';
import 'package:grocery_app/src/data/product_category.dart';
import 'package:grocery_app/src/data/wish_list_model.dart';
import 'package:grocery_app/src/logic/repo/product_repo.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/extensions.dart';
@@ -198,12 +199,7 @@ class ProductProvider extends ChangeNotifier {
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)) {
@@ -225,6 +221,112 @@ class ProductProvider extends ChangeNotifier {
}
}
// Future<bool> addToCart(BuildContext context, String productId) async
// {
// //context.showLoader(show: true);
// var data =
// {
// "productId": productId, "quantity": 1};
// try {
// var result = await _homeRepo.addToCart(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> cartItems = {}; // Stores added cart items
Map<String, bool> isLoading = {}; // Tracks loading state per product
Future<void> addToCart(BuildContext context, String productId) async {
if (cartItems.contains(productId)) return; // Prevent duplicate additions
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) {
cartItems.add(productId); // Update cart state on success
Fluttertoast.showToast(
msg: "Added to cart successfully!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 14.0,
);
},
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong"), backgroundColor: Colors.red),
);
}
isLoading[productId] = false;
notifyListeners();
}
bool isWishListItemLoadingg = true;
List<WishListItem> wishListItem = [];
int totalItems=0;
Future<void> gettAllWishList(BuildContext context) async {
var data = {};
var result = await _homeRepo.gettAllWishList(data);
return result.fold(
(error) {
isWishListItemLoadingg = false;
notifyListeners();
},
(response) {
wishListItem = response.items!;
totalItems=response.totalItems;
isWishListItemLoadingg = false;
notifyListeners();
},
);
}
}

View File

@@ -7,6 +7,7 @@ import 'package:grocery_app/src/data/allProduct_model.dart';
import 'package:grocery_app/src/data/banners.dart';
import 'package:grocery_app/src/data/best_dealProduct.dart';
import 'package:grocery_app/src/data/product_category.dart';
import 'package:grocery_app/src/data/wish_list_model.dart';
import 'package:grocery_app/src/logic/services/home_locator.dart';
class ProductRepo {
@@ -66,30 +67,42 @@ class ProductRepo {
}
}
FutureResult<String> addToWish(data) async
{
FutureResult<String> addToWish(data) async {
try {
var response = await _productService.addToWish(data);
final String model = response.toString();
final String model = response.toString();
return right(model);
} on DioException catch (e)
{
} on DioException catch (e) {
print("djhgfjdfhjg ${e}");
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<String> addToCart(data) async
{
FutureResult<String> addToCart(data) async {
try {
var response = await _productService.addToCart(data);
final String model = response.toString();
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 {
var response = await _productService.gettAllWishList(data);
WishListModel wishListModel=wishListModelFromJson(response.toString());
// final String model = response.toString();
return right(wishListModel);
} on DioException catch (e)
{
print("djhgfjdfhjg ${e}");
@@ -98,9 +111,6 @@ class ProductRepo {
}
}
FutureResult<BannerModel> getBanners(data, BuildContext context) async {
try {
var response = await _productService.getBanners(data);

View File

@@ -56,6 +56,14 @@ class ProductService extends ApiService {
return response;
}
Future gettAllWishList(data) async {
var response = await api.get(APIURL.gettAllWishList, data: jsonEncode(data));
return response;
}

View File

@@ -1,9 +1,13 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.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/utils/constants/assets_constant.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
@@ -129,6 +133,8 @@ class _BestDealScreenState extends State<BestDealScreen> {
),
),
),
body: itemBestdeal());
}
@@ -144,53 +150,84 @@ class _BestDealScreenState extends State<BestDealScreen> {
child: GridView.builder(
itemCount: provider.bestdeal.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.5),
crossAxisSpacing: 10,
mainAxisSpacing: 10),
crossAxisCount: 2,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.5),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
var bestdealproduct = provider.bestdeal[index];
return Container(
return
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 1,
offset: const Offset(5, 5),
),
]),
color: Colors.white,
borderRadius: BorderRadius.circular(15),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 1,
offset: const Offset(5, 5),
),
],
),
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 160,
width: MediaQuery.sizeOf(context).width,
// width: 150,
height: MediaQuery.of(context).size.height *
0.15, // Dynamic height
width: MediaQuery.of(context).size.width *
0.4, // Dynamic width
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15)),
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15),
),
child: Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 150,
width: 140,
Center(
child: AppNetworkImage(
height: MediaQuery.of(context).size.height * 0.13,
width: MediaQuery.of(context).size.width * 0.35,
imageUrl:
bestdealproduct.productImages?.first.url ??
"",
backGroundColor: Colors.transparent),
backGroundColor: Colors.transparent,
),
),
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border))
right: 5,
top: 5,
child: InkWell(
onTap: () async {
if (await SharedPrefUtils.getToken() !=
null) {
provider.toggleWishlist(
context, bestdealproduct.id!);
} else {
context.push(MyRoutes.LOGIN);
}
},
child: Icon(
provider.wishlist
.contains(bestdealproduct.id)
? Icons.favorite
: Icons.favorite_border,
color: provider.wishlist
.contains(bestdealproduct.id)
? Colors.red
: Colors.grey,
),
),
),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005),
Text(
bestdealproduct.name ?? "",
textAlign: TextAlign.left,
@@ -198,23 +235,19 @@ class _BestDealScreenState extends State<BestDealScreen> {
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 16),
),
const SizedBox(
height: 5,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005),
Text(
bestdealproduct.unit ?? "",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(
Colors.grey.withOpacity(0.8), 12),
),
const SizedBox(
height: 3,
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
Colors.grey.withOpacity(0.8),
12,
),
),
Spacer(),
Row(
children: [
Row(
@@ -242,13 +275,14 @@ class _BestDealScreenState extends State<BestDealScreen> {
),
],
),
const Spacer(),
Spacer(),
Align(
alignment: Alignment.centerRight,
child: Container(
height:
MediaQuery.of(context).size.height * 0.035,
width: MediaQuery.of(context).size.width * 0.1,
width: MediaQuery.of(context).size.width *
0.12, // Adjusted dynamic width
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
@@ -271,7 +305,145 @@ class _BestDealScreenState extends State<BestDealScreen> {
},
),
);
// Padding(
// padding: const EdgeInsets.all(15),
// child: GridView.builder(
// itemCount: provider.bestdeal.length,
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 2,
// childAspectRatio: MediaQuery.of(context).size.width /
// (MediaQuery.of(context).size.height / 1.5),
// crossAxisSpacing: 10,
// mainAxisSpacing: 10),
// itemBuilder: (context, index) {
// var bestdealproduct = provider.bestdeal[index];
// return Container(
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(15),
// boxShadow: [
// BoxShadow(
// color: Colors.grey.withOpacity(0.1),
// blurRadius: 1,
// offset: const Offset(5, 5),
// ),
// ]),
// child: Padding(
// padding: const EdgeInsets.all(5),
// child:
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Container(
// height: 100.h,
// width: MediaQuery.sizeOf(context).width,
// // width: 150,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(15)),
// child: Stack(
// alignment: Alignment.center,
// children: [
// AppNetworkImage(
// height: 90.h,
// width: 140,
// imageUrl:
// bestdealproduct.productImages?.first.url ??
// "",
// backGroundColor: Colors.transparent),
// Positioned(
// right: 5,
// top: 5,
// child: Icon(Icons.favorite_border))
// ],
// ),
// ),
// Text(
// bestdealproduct.name ?? "",
// textAlign: TextAlign.left,
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(APPCOLOR.balck1A1A1A, 16),
// ),
// const SizedBox(
// height: 5,
// ),
// Text(
// bestdealproduct.unit ?? "",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(
// Colors.grey.withOpacity(0.8), 12),
// ),
// const SizedBox(
// height: 3,
// ),
// SizedBox(
// height: MediaQuery.of(context).size.height * 0.005,
// ),
// Spacer(),
// Row(
// children: [
// Row(
// children: [
// Text(
// "\$${bestdealproduct.discountPrice ?? ""} ",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customSemiBold(Colors.black, 12),
// ),
// Text(
// "\$${bestdealproduct.basePrice ?? ""}",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context
// .customMedium(
// Colors.grey.withOpacity(0.8),
// 12,
// )
// .copyWith(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// ),
// const Spacer(),
// Align(
// alignment: Alignment.centerRight,
// child: Container(
// height:
// MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ],
// ),
// ],
// ),
// ),
// );
// },
// ),
// );
}
});
}
}

View File

@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/data/product_model.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/header.dart';
import 'package:grocery_app/src/ui/widgets/custom_title.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:provider/provider.dart';
class FavouriteScreen extends StatefulWidget {
@override
@@ -16,18 +18,21 @@ class _FavouriteScreenState extends State<FavouriteScreen>
late AnimationController _animationController;
late Animation<double> _animation;
List<ProductModel> _favProducts = [
ProductModel("", 'Bell pepper red', '7pcs', '\$4.99'),
ProductModel("", 'Ginger', '1kg', '\$4.99'),
ProductModel("", 'Egg pasta', '30gm', '\$15.9'),
];
// List<ProductModel> _favProducts = [
// ProductModel("", 'Bell pepper red', '7pcs', '\$4.99'),
// ProductModel("", 'Ginger', '1kg', '\$4.99'),
// ProductModel("", 'Egg pasta', '30gm', '\$15.9'),
// ];
@override
void initState() {
Provider.of<ProductProvider>(context, listen: false)
.gettAllWishList(context);
_animationController = AnimationController(
duration: const Duration(milliseconds: 1000),
vsync: this,
);
super.initState();
}
@@ -41,6 +46,82 @@ class _FavouriteScreenState extends State<FavouriteScreen>
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
// floatingActionButton: Padding(
// padding: const EdgeInsets.only(left: 30),
// child: Container(
// height: 80,
// width: MediaQuery.sizeOf(context).width,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(15)),
// child: Padding(
// padding: const EdgeInsets.all(10),
// child: Row(
// children: [
// SizedBox(
// width: 80,
// child: Stack(
// children: [
// Container(
// height: 70,
// width: 70,
// decoration: BoxDecoration(
// color: Colors.white.withOpacity(0.5),
// borderRadius: BorderRadius.circular(10)),
// ),
// const Positioned(
// left: 20,
// bottom: 0,
// top: 0,
// right: 0,
// child: AppNetworkImage(
// height: 70,
// width: 70,
// radius: 10,
// imageUrl:
// "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
// backGroundColor: Colors.white,
// ),
// ),
// ],
// ),
// ),
// const SizedBox(
// width: 10,
// ),
// Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// '2 Items',
// style: context.customRegular(Colors.white, 18),
// ),
// Text(
// '\$25',
// style: context.customExtraBold(Colors.white, 20),
// )
// ],
// ),
// const Spacer(),
// Text(
// 'View Cart',
// style: context.customMedium(Colors.white, 24),
// ),
// const SizedBox(
// width: 10,
// ),
// const Icon(
// Icons.arrow_forward,
// color: Colors.white,
// size: 35,
// ),
// ],
// ),
// ),
// ),
// ),
body: Padding(
padding: context.bodyAllPadding.copyWith(
top: 0,
@@ -48,105 +129,95 @@ class _FavouriteScreenState extends State<FavouriteScreen>
child: Column(
children: [
Header(),
// CustomTitle(title: 'Favourite'),
Expanded(
child: ListView.separated(
itemCount: _favProducts.length,
shrinkWrap: true,
padding: const EdgeInsets.all(16),
itemBuilder: (_, index) {
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(
(0.5 / _favProducts.length) * index,
1,
curve: Curves.easeOut,
),
),
);
_animationController.forward(from: 0);
return AnimatedBuilder(
animation: _animationController,
builder: (_, child) {
return FadeTransition(
opacity: _animation,
child: Transform(
transform: Matrix4.translationValues(
0.0,
50 * (1.0 - _animation.value),
0.0,
),
child: child,
),
);
},
child: ListTile(
onTap: () {},
leading: Container(
itemList(),
Consumer<ProductProvider>(
builder: (context, wishListProvider, _) {
return wishListProvider.totalItems > 0
? Padding(
padding: const EdgeInsets.only(),
child: Container(
height: 80,
width: MediaQuery.sizeOf(context).width,
decoration: BoxDecoration(
color: Colors.greenAccent.withOpacity(0.1),
borderRadius: BorderRadius.circular(5),
),
child: AppNetworkImage(
height: 80,
width: 80,
imageUrl:
'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
),
),
// Image.asset(_favProducts[index].productImage),
title: Text(_favProducts[index].productName),
subtitle: Text(_favProducts[index].quantity),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(_favProducts[index].amount),
Icon(
Icons.navigate_next_rounded,
size: 32,
color: APPCOLOR.gray,
)
],
),
),
);
},
separatorBuilder: (_, index) {
_animation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(
(0.5 / _favProducts.length) * index,
1,
curve: Curves.easeOut,
),
),
);
_animationController.forward(from: 0);
return AnimatedBuilder(
animation: _animationController,
builder: (_, child) {
return FadeTransition(
opacity: _animation,
child: Transform(
transform: Matrix4.translationValues(
0.0,
50 * (1.0 - _animation.value),
0.0,
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(15)),
child: Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
SizedBox(
width: 80,
child: Stack(
children: [
Container(
height: 70,
width: 70,
decoration: BoxDecoration(
color:
Colors.white.withOpacity(0.5),
borderRadius:
BorderRadius.circular(10)),
),
const Positioned(
left: 20,
bottom: 0,
top: 0,
right: 0,
child: AppNetworkImage(
height: 70,
width: 70,
radius: 10,
imageUrl:
"https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
backGroundColor: Colors.white,
),
),
],
),
),
const SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
'2 Items',
style: context.customRegular(
Colors.white, 18),
),
Text(
'\$25',
style: context.customExtraBold(
Colors.white, 20),
)
],
),
const Spacer(),
Text(
'View Cart',
style: context.customMedium(Colors.white, 24),
),
const SizedBox(
width: 10,
),
const Icon(
Icons.arrow_forward,
color: Colors.white,
size: 35,
),
],
),
child: child,
),
);
},
child: Divider(),
);
},
),
),
),
)
: SizedBox.shrink();
}),
// Padding(
// padding:
// const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 78),
@@ -161,4 +232,308 @@ class _FavouriteScreenState extends State<FavouriteScreen>
),
);
}
Widget itemList() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isWishListItemLoadingg) {
return Expanded(child: Center(child: CircularProgressIndicator()));
} else if (provider.wishListItem.isEmpty) {
return Expanded(child: Center(child: Text('No products available')));
} else {
return Expanded(
child: ListView.separated(
itemCount: provider.wishListItem.length,
shrinkWrap: true,
padding: const EdgeInsets.all(16),
itemBuilder: (_, index) {
final item = provider.wishListItem[index];
final product = item.product!;
final productId = product.id!;
final animation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(
(0.5 / provider.wishListItem.length) * index,
1,
curve: Curves.easeOut,
),
),
);
_animationController.forward(from: 0);
return Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
blurRadius: 5,
offset: Offset(2, 2),
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Flexible(
flex: 3,
child: Container(
height: 100,
width: 100,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: APPCOLOR.bgGrey,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: AppNetworkImage(
imageUrl:
"https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png",
backGroundColor: APPCOLOR.bgGrey,
height: 20,
width: 20,
),
),
),
),
Flexible(
flex: 4,
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
product.name ?? "",
style: context.customMedium(
APPCOLOR.balck1A1A1A, 14),
//textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
"\$${product.discountPrice}",
style:
context.customSemiBold(Colors.black, 14),
),
SizedBox(width: 5),
Text(
"\$${product.basePrice ?? ""}",
style: context
.customMedium(
Colors.grey.withOpacity(0.8), 12)
.copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
),
SizedBox(height: 10),
// Add to Cart Button
],
),
),
),
Spacer(),
GestureDetector(
onTap: provider.isLoading[productId] ?? false
? null
: () => provider.addToCart(context, productId),
child: Container(
height: 35,
width: 50,
decoration: BoxDecoration(
color: provider.cartItems.contains(productId)
? Colors.grey
: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: provider.isLoading[productId] ?? false
? CircularProgressIndicator(
color: Colors.white, strokeWidth: 2)
: Text(
provider.cartItems.contains(productId)
? 'Added'
: 'Add',
style:
context.customRegular(Colors.white, 14),
),
),
),
),
],
),
);
},
separatorBuilder: (_, __) => Divider(),
),
);
// Expanded(
// child: ListView.separated(
// itemCount: provider.wishListItem.length,
// shrinkWrap: true,
// padding: const EdgeInsets.all(16),
// itemBuilder: (_, index) {
// _animation = Tween<double>(begin: 0.0, end: 1.0).animate(
// CurvedAnimation(
// parent: _animationController,
// curve: Interval(
// (0.5 / provider.wishListItem.length) * index,
// 1,
// curve: Curves.easeOut,
// ),
// ),
// );
// _animationController.forward(from: 0);
// var item = provider.wishListItem[index];
// return AnimatedBuilder(
// animation: _animationController,
// builder: (_, child) {
// return FadeTransition(
// opacity: _animation,
// child: Transform(
// transform: Matrix4.translationValues(
// 0.0,
// 50 * (1.0 - _animation.value),
// 0.0,
// ),
// child: child,
// ),
// );
// },
// child: ListTile(
// onTap: () {},
// leading: Container(
// decoration: BoxDecoration(
// color: Colors.greenAccent.withOpacity(0.1),
// borderRadius: BorderRadius.circular(5),
// ),
// child: AppNetworkImage(
// height: 80,
// width: 80,
// imageUrl:
// 'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
// backGroundColor: APPCOLOR.bgGrey,
// radius: 10,
// ),
// ),
// // Image.asset(_favProducts[index].productImage),
// title: Text(item.product!.name ?? ""),
// subtitle: Text(item.product!.unit ?? ""),
// trailing: Row(
// children: [
// Column(
// mainAxisSize: MainAxisSize.min,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text("\$" + item.product!.discountPrice),
// Text(
// "\$${item.product!.basePrice ?? ""}",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context
// .customMedium(
// Colors.grey.withOpacity(0.8),
// 12,
// )
// .copyWith(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// ),
// Align(
// alignment: Alignment.centerRight,
// child: GestureDetector(
// // onTap: provider.isLoading[bestdealproduct.id] ??
// // false
// // ? null
// // : () => provider.addToCart(
// // context, bestdealproduct.id!),
// child: Container(
// height: MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color:
// // provider.cartItems
// // .contains(bestdealproduct.id)
// // ? Colors.grey
// // :
// APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child:
// // provider.isLoading[
// // bestdealproduct.id] ??
// // false
// // ? CircularProgressIndicator(
// // color: Colors.white, strokeWidth: 2)
// // :
// Text(
// // provider.cartItems.contains(
// // bestdealproduct.id)
// // ? 'Added'
// // :
// 'Add',
// style: context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ),
// ],
// ),
// ),
// );
// },
// separatorBuilder: (_, index) {
// _animation = Tween<double>(begin: 0.0, end: 1.0).animate(
// CurvedAnimation(
// parent: _animationController,
// curve: Interval(
// (0.5 / provider.wishListItem.length) * index,
// 1,
// curve: Curves.easeOut,
// ),
// ),
// );
// _animationController.forward(from: 0);
// return AnimatedBuilder(
// animation: _animationController,
// builder: (_, child) {
// return FadeTransition(
// opacity: _animation,
// child: Transform(
// transform: Matrix4.translationValues(
// 0.0,
// 50 * (1.0 - _animation.value),
// 0.0,
// ),
// child: child,
// ),
// );
// },
// child: Divider(),
// );
// },
// ),
// );
}
});
}
}

View File

@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.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/utils/constants/assets_constant.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
@@ -36,6 +39,8 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
width: 20,
child: InkWell(
onTap: () {
Provider.of<ProductProvider>(context, listen: false)
.gettAllProduct(context, "");
Navigator.of(context).pop();
},
child: SvgPicture.asset(
@@ -71,8 +76,7 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
);
}
Widget productWidget()
{
Widget productWidget() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isLoadingg) {
return Padding(
@@ -143,7 +147,26 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border),
child: InkWell(
onTap: () async {
if (await SharedPrefUtils.getToken() !=
null)
{
provider.toggleWishlist(
context, product.id!);
} else {
context.push(MyRoutes.LOGIN);
}
},
child: Icon(
provider.wishlist.contains(product.id)
? Icons.favorite
: Icons.favorite_border,
color: provider.wishlist.contains(product.id)
? Colors.red
: Colors.grey,
),
),
),
],
),

View File

@@ -1,5 +1,6 @@
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.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';
@@ -235,8 +236,7 @@ class _HomeScreenState extends State<HomeScreen> {
child: InkWell(
onTap: () async {
if (await SharedPrefUtils.getToken() !=
null)
{
null) {
provider.toggleWishlist(
context, bestdealproduct.id!);
} else {
@@ -285,6 +285,7 @@ class _HomeScreenState extends State<HomeScreen> {
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
),
const Spacer(),
Row(
children: [
Row(
@@ -313,22 +314,77 @@ class _HomeScreenState extends State<HomeScreen> {
),
],
),
// Align(
// alignment: Alignment.centerRight,
// child: InkWell(
// onTap: () async {
// bool success = await provider.addToCart(context, bestdealproduct.id!);
// if (success) {
// Fluttertoast.showToast(
// msg: "Product added to cart!",
// toastLength: Toast.LENGTH_SHORT,
// gravity: ToastGravity.BOTTOM,
// backgroundColor: Colors.green,
// textColor: Colors.white,
// fontSize: 14.0,
// );
// }
// },
// child: Container(
// height:
// MediaQuery.of(context).size.height * 0.035,
// width: MediaQuery.of(context).size.width * 0.1,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// ),
// ),
// ),
// ),
// ),
const Spacer(),
Align(
alignment: Alignment.centerRight,
child: Container(
height:
MediaQuery.of(context).size.height * 0.035,
width: MediaQuery.of(context).size.width * 0.1,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Add',
style:
context.customRegular(Colors.white, 12),
child: GestureDetector(
onTap: provider.isLoading[bestdealproduct.id] ??
false
? null
: () => provider.addToCart(
context, bestdealproduct.id!),
child: Container(
height: MediaQuery.of(context).size.height *
0.035,
width:
MediaQuery.of(context).size.width * 0.1,
decoration: BoxDecoration(
color: provider.cartItems
.contains(bestdealproduct.id)
? Colors.grey
: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: provider.isLoading[
bestdealproduct.id] ??
false
? CircularProgressIndicator(
color: Colors.white, strokeWidth: 2)
: Text(
provider.cartItems.contains(
bestdealproduct.id)
? 'Added'
: 'Add',
style: context.customRegular(
Colors.white, 12),
),
),
),
),

View File

@@ -29,12 +29,12 @@ class _OnBoardingScreenState extends State<OnBoardingScreen> {
SharedPrefUtils.setFreshInstall(isFresh: false).then(
(value) => context.clearAndPush(routePath: MyRoutes.BOTTOMNAV, args: 0),
);
}
// Navigator.pushReplacement(context, MaterialPageRoute(
// builder: (context) {
// return const LoginScreen();
// },
// ));
skipbyarrowFunction() {
SharedPrefUtils.setFreshInstall(isFresh: false).then(
(value) => context.clearAndPush(routePath: MyRoutes.LOGIN, args: 0),
);
}
onChangedFunction(int index) {
@@ -446,7 +446,8 @@ class _OnBoardingScreenState extends State<OnBoardingScreen> {
child: Center(
child: InkWell(
onTap: () {
skipFunction();
skipbyarrowFunction();
//skipFunction();
},
child: Container(
height: 70,

View File

@@ -29,21 +29,11 @@ class _SplashScreenState extends State<SplashScreen> {
Future.delayed(const Duration(seconds: 2), () async {
if (await SharedPrefUtils.isFreshInstall()) {
context.clearAndPush(routePath: MyRoutes.ONBOARDING);
} else
{
print("kdsbfjhdkjfdfghv ${await SharedPrefUtils.getToken()}");
if (await SharedPrefUtils.getToken() == "1" ||
await SharedPrefUtils.getToken() == null) {
// context.clearAndPush(routePath: MyRoutes.SELECTACCOUNT);
} else {
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
}
} else {
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
}
});
Future.delayed(const Duration(seconds: 2), () async {
context.clearAndPush(routePath: MyRoutes.ONBOARDING);
});
super.initState();
}