implementsProdctApi

This commit is contained in:
bestonemitRam
2025-01-27 01:11:20 +05:30
parent 9e559bdded
commit cbeaa2af5c
24 changed files with 2231 additions and 1026 deletions

View File

@@ -5,23 +5,27 @@ class APIURL {
static const String verifyOtp = "${BASE_URL}auth/verify-otp/customer";
static const String login = "${BASE_URL}auth/login/vendor";
static const String customerRegister = "${BASE_URL}auth/register/customer";
static const String getStore = "${BASE_URL}stores/";
static const String getAllProduct = "${BASE_URL}products";
static const String getBanners = "${BASE_URL}banners";
static const String customerLogOut = "${BASE_URL}auth/logout/customer";
static const String getBestDealProduct = "${BASE_URL}products/best-deals";
static const String getAllcategory = "${BASE_URL}categories";
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 get_category = "${BASE_URL}categories";
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";
static const String refresh_token = "${BASE_URL}auth/refresh-token";
static const String createProduct = "${BASE_URL}products";
static const String customerLogOut = "${BASE_URL}/auth/logout/customer";
static const String uploadImage = "${BASE_URL}images/upload";
static const String deleteProduct = "${BASE_URL}products/";
static const String updateProduct = "${BASE_URL}products/";

View File

@@ -4,7 +4,9 @@ import 'package:dio/dio.dart';
import 'package:get_it/get_it.dart';
import 'package:grocery_app/src/core/network_services/dio_client.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/src/logic/services/auth_service_locator.dart';
import 'package:grocery_app/src/logic/services/home_locator.dart';
@@ -19,7 +21,7 @@ class ServiceLocator
getIt.registerSingleton(Dio());
getIt.registerSingleton(DioClient(getIt<Dio>()));
getIt.registerSingleton(AuthServices());
// getIt.registerSingleton(ProductService());
getIt.registerSingleton(ProductService());
// getIt.registerSingleton(StoreService());
// getIt.registerSingleton(HomeService());
@@ -27,7 +29,7 @@ class ServiceLocator
// Repos
getIt.registerSingleton(AuthRepo(getIt<AuthServices>()));
// getIt.registerSingleton(ProductRepo(getIt<ProductService>()));
getIt.registerSingleton(ProductRepo(getIt<ProductService>()));
// getIt.registerSingleton(StoreRepo(getIt<StoreService>()));
// getIt.registerSingleton(HomeRepo(getIt<HomeService>()));

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:grocery_app/src/ui/bottomnavigation/bottom_bar_widget.dart';
import 'package:grocery_app/src/ui/entername/enter_fullname_screen.dart';
import 'package:grocery_app/src/ui/fruitvegidetail/fruit_veggie_detail.dart';
import 'package:grocery_app/src/ui/login/login_screen.dart';
import 'package:grocery_app/src/ui/onboarding/on_boarding_screen.dart';
import 'package:grocery_app/src/ui/otp/otp_screen.dart';
@@ -51,6 +52,11 @@ class MyRoutes {
name: BOTTOMNAV,
pageBuilder: (context, state) => const BottomBarWidget(),
),
animatedGoRoute(
path: FRUITVEGGIEDETAIL,
name: FRUITVEGGIEDETAIL,
pageBuilder: (context, state) => const FruitVeggieDetail(),
),
// animatedGoRoute(
// path: TERMANDCONDITIONS,
@@ -176,10 +182,11 @@ class MyRoutes {
/// Route constants
static const SPLASH = "/";
static const FULLNAME = "/fullname";
static const BOTTOMNAV = "/bottomnav";
static const HOME = "/home";
static const FRUITVEGGIEDETAIL = "/FruitVeggieDetail";
static const SELECTACCOUNT = "/selectAccount";
static const DASHBOARD = "/dashboard";

93
lib/src/data/banners.dart Normal file
View File

@@ -0,0 +1,93 @@
// To parse this JSON data, do
//
// final banner = bannerFromJson(jsonString);
import 'dart:convert';
BannerModel bannerFromJson(String str) => BannerModel.fromJson(json.decode(str));
String bannerToJson(BannerModel data) => json.encode(data.toJson());
class BannerModel {
List<BannerData>? data;
Meta? meta;
BannerModel({
this.data,
this.meta,
});
factory BannerModel.fromJson(Map<String, dynamic> json) => BannerModel(
data: List<BannerData>.from(json["data"].map((x) => BannerData.fromJson(x))),
meta: Meta.fromJson(json["meta"]),
);
Map<String, dynamic> toJson() => {
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
"meta": meta!.toJson(),
};
}
class BannerData {
dynamic? id;
dynamic? imageUrl;
dynamic? redirectUrl;
dynamic altText;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
BannerData({
this.id,
this.imageUrl,
this.redirectUrl,
this.altText,
this.isActive,
this.createdAt,
this.updatedAt,
});
factory BannerData.fromJson(Map<String, dynamic> json) => BannerData(
id: json["id"],
imageUrl: json["imageUrl"],
redirectUrl: json["redirectUrl"],
altText: json["altText"],
isActive: json["isActive"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
);
Map<String, dynamic> toJson() => {
"id": id,
"imageUrl": imageUrl,
"redirectUrl": redirectUrl,
"altText": altText,
"isActive": isActive,
"createdAt": createdAt,
"updatedAt": updatedAt,
};
}
class Meta {
int? total;
int? page;
int? lastPage;
Meta({
this.total,
this.page,
this.lastPage,
});
factory Meta.fromJson(Map<String, dynamic> json) => Meta(
total: json["total"],
page: json["page"],
lastPage: json["lastPage"],
);
Map<String, dynamic> toJson() => {
"total": total,
"page": page,
"lastPage": lastPage,
};
}

View File

@@ -0,0 +1,317 @@
// To parse this JSON data, do
//
// final bestDealProduct = bestDealProductFromJson(jsondynamic);
import 'dart:convert';
BestDealProduct bestDealProductFromJson(dynamic str) => BestDealProduct.fromJson(json.decode(str));
dynamic bestDealProductToJson(BestDealProduct data) => json.encode(data.toJson());
class BestDealProduct {
List<BestDeal>? data;
Meta? meta;
BestDealProduct({
this.data,
this.meta,
});
factory BestDealProduct.fromJson(Map<dynamic, dynamic> json) => BestDealProduct(
data: List<BestDeal>.from(json["data"].map((x) => BestDeal.fromJson(x))),
meta: Meta.fromJson(json["meta"]),
);
Map<dynamic, dynamic> toJson() => {
"data": List<dynamic>.from(data!.map((x) => x.toJson())),
"meta": meta!.toJson(),
};
}
class BestDeal {
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;
DateTime? createdAt;
DateTime? updatedAt;
dynamic storeId;
dynamic categoryId;
dynamic productTypeId;
dynamic timeSlotId;
Store? store;
Category? category;
List<ProductImage>? productImages;
List<dynamic>? productReview;
dynamic averageRating;
dynamic discountPercentage;
double? bestDealScore;
BestDeal({
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.createdAt,
this.updatedAt,
this.storeId,
this.categoryId,
this.productTypeId,
this.timeSlotId,
this.store,
this.category,
this.productImages,
this.productReview,
this.averageRating,
this.discountPercentage,
this.bestDealScore,
});
factory BestDeal.fromJson(Map<dynamic, dynamic> json) => BestDeal(
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"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
storeId: json["storeId"],
categoryId: json["categoryId"],
productTypeId: json["productTypeId"],
timeSlotId: json["timeSlotId"],
store: Store.fromJson(json["store"]),
category: Category.fromJson(json["category"]),
productImages: List<ProductImage>.from(json["productImages"].map((x) => ProductImage.fromJson(x))),
productReview: List<dynamic>.from(json["ProductReview"].map((x) => x)),
averageRating: json["averageRating"],
discountPercentage: json["discountPercentage"],
bestDealScore: json["bestDealScore"].toDouble(),
);
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,
"createdAt": createdAt,
"updatedAt": updatedAt,
"storeId": storeId,
"categoryId": categoryId,
"productTypeId": productTypeId,
"timeSlotId": timeSlotId,
"store": store!.toJson(),
"category": category!.toJson(),
"productImages": List<dynamic>.from(productImages!.map((x) => x.toJson())),
"ProductReview": List<dynamic>.from(productReview!.map((x) => x)),
"averageRating": averageRating,
"discountPercentage": discountPercentage,
"bestDealScore": bestDealScore,
};
}
class Category {
dynamic id;
dynamic name;
dynamic description;
dynamic image;
dynamic slug;
dynamic level;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
dynamic parentCategoryId;
dynamic path;
Category({
this.id,
this.name,
this.description,
this.image,
this.slug,
this.level,
this.isActive,
this.createdAt,
this.updatedAt,
this.parentCategoryId,
this.path,
});
factory Category.fromJson(Map<dynamic, dynamic> json) => Category(
id: json["id"],
name: json["name"],
description: json["description"],
image: json["image"],
slug: json["slug"],
level: json["level"],
isActive: json["isActive"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
parentCategoryId: json["parentCategoryId"],
path: json["path"],
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"image": image,
"slug": slug,
"level": level,
"isActive": isActive,
"createdAt": createdAt,
"updatedAt": updatedAt,
"parentCategoryId": parentCategoryId,
"path": path,
};
}
class ProductImage {
dynamic id;
dynamic url;
bool? isDefault;
dynamic productId;
ProductImage({
this.id,
this.url,
this.isDefault,
this.productId,
});
factory ProductImage.fromJson(Map<dynamic, dynamic> json) => ProductImage(
id: json["id"],
url: json["url"],
isDefault: json["isDefault"],
productId: json["productId"],
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"url": url,
"isDefault": isDefault,
"productId": productId,
};
}
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;
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,
});
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"],
);
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,
};
}
class Meta {
dynamic total;
dynamic page;
dynamic lastPage;
Meta({
this.total,
this.page,
this.lastPage,
});
factory Meta.fromJson(Map<dynamic, dynamic> json) => Meta(
total: json["total"],
page: json["page"],
lastPage: json["lastPage"],
);
Map<dynamic, dynamic> toJson() => {
"total": total,
"page": page,
"lastPage": lastPage,
};
}

View File

@@ -0,0 +1,212 @@
import 'dart:convert';
ProductCategory productCategoryFromJson(dynamic str) =>
ProductCategory.fromJson(json.decode(str));
dynamic productCategoryToJson(ProductCategory data) =>
json.encode(data.toJson());
class ProductCategory {
List<Datum>? data;
Meta? meta;
ProductCategory({
this.data,
this.meta,
});
factory ProductCategory.fromJson(Map<dynamic, dynamic> json) =>
ProductCategory(
data: json["data"] == null
? []
: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
meta: json["meta"] == null ? null : Meta.fromJson(json["meta"]),
);
Map<dynamic, dynamic> toJson() => {
"data": data == null
? []
: List<dynamic>.from(data!.map((x) => x.toJson())),
"meta": meta?.toJson(),
};
}
class Datum {
dynamic id;
dynamic name;
dynamic description;
dynamic image;
dynamic slug;
int? level;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
dynamic parentCategoryId;
dynamic path;
Category? parentCategory;
List<Category>? childCategories;
Datum({
this.id,
this.name,
this.description,
this.image,
this.slug,
this.level,
this.isActive,
this.createdAt,
this.updatedAt,
this.parentCategoryId,
this.path,
this.parentCategory,
this.childCategories,
});
factory Datum.fromJson(Map<dynamic, dynamic> json) => Datum(
id: json["id"],
name: json["name"],
description: json["description"],
image: json["image"],
slug: json["slug"],
level: json["level"],
isActive: json["isActive"],
createdAt: json["createdAt"] == null
? null
: DateTime.parse(json["createdAt"]),
updatedAt: json["updatedAt"] == null
? null
: DateTime.parse(json["updatedAt"]),
parentCategoryId: json["parentCategoryId"],
path: json["path"],
parentCategory: json["parentCategory"] == null
? null
: Category.fromJson(json["parentCategory"]),
childCategories: json["childCategories"] == null
? []
: List<Category>.from(
json["childCategories"].map((x) => Category.fromJson(x))),
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"image": image,
"slug": slug,
"level": level,
"isActive": isActive,
"createdAt": createdAt?.toIso8601String(),
"updatedAt": updatedAt?.toIso8601String(),
"parentCategoryId": parentCategoryId,
"path": path,
"parentCategory": parentCategory?.toJson(),
"childCategories": childCategories == null
? []
: List<dynamic>.from(childCategories!.map((x) => x.toJson())),
};
}
class Category {
dynamic id;
dynamic name;
dynamic description;
dynamic image;
dynamic slug;
int? level;
bool? isActive;
DateTime? createdAt;
DateTime? updatedAt;
dynamic parentCategoryId;
dynamic path;
List<Category>? childCategories;
Category({
this.id,
this.name,
this.description,
this.image,
this.slug,
this.level,
this.isActive,
this.createdAt,
this.updatedAt,
this.parentCategoryId,
this.path,
this.childCategories,
});
factory Category.fromJson(Map<dynamic, dynamic> json) => Category(
id: json["id"],
name: json["name"],
description: json["description"],
image: json["image"],
slug: json["slug"],
level: json["level"],
isActive: json["isActive"],
createdAt: json["createdAt"] == null
? null
: DateTime.parse(json["createdAt"]),
updatedAt: json["updatedAt"] == null
? null
: DateTime.parse(json["updatedAt"]),
parentCategoryId: json["parentCategoryId"],
path: json["path"],
childCategories: json["childCategories"] == null
? []
: List<Category>.from(
json["childCategories"].map((x) => Category.fromJson(x))),
);
Map<dynamic, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"image": image,
"slug": slug,
"level": level,
"isActive": isActive,
"createdAt": createdAt?.toIso8601String(),
"updatedAt": updatedAt?.toIso8601String(),
"parentCategoryId": parentCategoryId,
"path": path,
"childCategories": childCategories == null
? []
: List<dynamic>.from(childCategories!.map((x) => x.toJson())),
};
}
class Meta {
int? total;
int? page;
int? limit;
int? lastPage;
bool? hasNextPage;
bool? hasPreviousPage;
Meta({
this.total,
this.page,
this.limit,
this.lastPage,
this.hasNextPage,
this.hasPreviousPage,
});
factory Meta.fromJson(Map<dynamic, dynamic> json) => Meta(
total: json["total"],
page: json["page"],
limit: json["limit"],
lastPage: json["lastPage"],
hasNextPage: json["hasNextPage"],
hasPreviousPage: json["hasPreviousPage"],
);
Map<dynamic, dynamic> toJson() => {
"total": total,
"page": page,
"limit": limit,
"lastPage": lastPage,
"hasNextPage": hasNextPage,
"hasPreviousPage": hasPreviousPage,
};
}

View File

@@ -160,7 +160,7 @@ class AuthProvider extends ChangeNotifier {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong. Please try again."),
content: Text("Something went wrong. Please try again. "),
backgroundColor: Colors.red,
),
);

View File

@@ -1,21 +1,155 @@
import 'package:flutter/material.dart';
import 'package:grocery_app/src/core/network_services/service_locator.dart';
import 'package:grocery_app/src/logic/repo/home_repo.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
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/logic/repo/product_repo.dart';
import 'package:grocery_app/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/extensions.dart';
class ProductProvider extends ChangeNotifier {
final _homeRepo = getIt<ProductRepo>();
Future<bool> gettAllProduct(BuildContext context) async {
bool isLoadingg = true;
List<Product> products = [];
Future<void> gettAllProduct(BuildContext context) async {
var data = {};
var result = await _homeRepo.getAllProduct(data, context);
return result.fold(
(error) {
return true;
isLoadingg = false;
notifyListeners();
},
(response) {
return true;
products = response.data!;
isLoadingg = false;
notifyListeners();
},
);
}
List<BestDeal> bestdeal = [];
bool isBestdealingloading = true;
Future<void> getBestDealProduct(BuildContext context) async {
var data = {};
var result = await _homeRepo.getBestDealProduct(data, context);
return result.fold(
(error) {
isBestdealingloading = false;
notifyListeners();
},
(response) {
bestdeal = response.data!;
isBestdealingloading = false;
notifyListeners();
},
);
}
List<Datum> categoryList = [];
bool iscategroyloading = true;
Future<void> getAllcategory(BuildContext context) async {
var data = {};
var result = await _homeRepo.getAllcategory(data, context);
return result.fold(
(error) {
print("djhgfjdfhjg ${error}");
iscategroyloading = false;
notifyListeners();
},
(response) {
print("jdshfjghdhfjhgjd");
categoryList = response.data!;
iscategroyloading = false;
notifyListeners();
},
);
}
List<BannerData> banner = [];
bool isBannerLoading = true;
Future<void> getBanners(BuildContext context) async {
var data = {};
var result = await _homeRepo.getBanners(data, context);
return result.fold(
(error) {
isBannerLoading = false;
notifyListeners();
},
(response) {
banner = response.data!;
isBannerLoading = false;
notifyListeners();
},
);
}
Future<bool> customerLogOut(BuildContext context) async {
context.showLoader(show: true);
var data = {};
try {
var result = await _homeRepo.customerLogOut(data);
context.showLoader(show: false);
return result.fold(
(error) {
// Show error Snackbar
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(error.message),
backgroundColor: Colors.red,
),
);
return false; // Login failed
},
(response) async {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Store created successful!"),
backgroundColor: Colors.green,
),
);
await SharedPrefUtils.clear();
context.clearAndPush(routePath: MyRoutes.LOGIN);
return true;
},
);
} catch (e) {
context.showLoader(show: false);
print("Unexpected error: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong. Please try again."),
backgroundColor: Colors.red,
),
);
return false;
}
}
int _activeIndex = 0;
int get activeIndex => _activeIndex;
void setActiveIndex(int index) {
_activeIndex = index;
notifyListeners();
}
}

View File

@@ -1,63 +0,0 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fpdart/fpdart.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/allProduct_model.dart';
import 'package:grocery_app/src/logic/services/home_locator.dart';
class ProductRepo {
final ProductService _productService;
ProductRepo(this._productService);
FutureResult<String> getAllProduct(data, BuildContext context) async {
try {
var response = await _productService.getAllProduct(data);
AllProductModel loginResponse = allProductModelFromJson(response.toString());
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);
// final VendorModel vendorModel = vendorModelFromJson(response.toString());
// if (vendorModel != null)
// {
// SharedPrefUtils.USER_NAME =
// vendorModel.firstName + " " + vendorModel.lastName;
// SharedPrefUtils.PHONE = vendorModel.phone;
// print("dkfjhdkfhkfk ${SharedPrefUtils.USER_NAME}");
// await SharedPrefUtils.setStoreId(storeId: vendorModel.storeId ?? "");
// }
// final String model = response.toString();
// return right(vendorModel);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
}

View File

@@ -1,126 +1,123 @@
// import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:fpdart/fpdart.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/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/logic/services/home_locator.dart';
// import 'package:dio/dio.dart';
// import 'package:fpdart/fpdart.dart';
// import 'package:vendor_app/src/core/utiils_lib/custom_dio_exception.dart';
// import 'package:vendor_app/src/core/utiils_lib/response_type_def.dart';
// import 'package:vendor_app/src/core/utiils_lib/shared_pref_utils.dart';
// import 'package:vendor_app/src/data/ProductCategoryModel.dart';
// import 'package:vendor_app/src/data/prdouct_model.dart';
// import 'package:vendor_app/src/data/upload_image.dart';
// import 'package:vendor_app/src/data/vendor_otpModel.dart';
// import 'package:vendor_app/src/logic/services/product_locator.dart';
// import 'package:vendor_app/src/logic/services/service_locator.dart';
class ProductRepo {
final ProductService _productService;
// class ProductRepo {
// final ProductService _productServices;
ProductRepo(this._productService);
// ProductRepo(this._productServices);
FutureResult<AllProductModel> getAllProduct(data, BuildContext context) async {
try {
var response = await _productService.getAllProduct(data);
// FutureResult<PrdouctModel> getProduct(data) async {
// try {
// var response = await _productServices.getProduct(data);
AllProductModel loginResponse =
allProductModelFromJson(response.toString());
// final PrdouctModel prdouctModel =
// prdouctModelFromJson(response.toString());
final String model = response.toString();
// if (prdouctModel.data!.isNotEmpty)
// {
// print("check data are fetch are note");
// }
return right(loginResponse);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
// // final String model = response.toString();
FutureResult<BestDealProduct> getBestDealProduct(data, BuildContext context) async {
try {
var response = await _productService.getBestDealProduct(data);
// return right(prdouctModel);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
BestDealProduct loginResponse =
bestDealProductFromJson(response.toString());
// FutureResult<List<ProductCategoryModel>> getCategoryByLevel(data) async
// {
// try {
// var response = await _productServices.getCategoryByLevel(data);
final String model = response.toString();
// final List<ProductCategoryModel> productModels = (response.data as List)
// .map((item) => ProductCategoryModel.fromJson(item))
// .toList();
// if (response != null && response.data != null)
// {
// // Parse the response data into a list of ProductCategoryModel
// final List<ProductCategoryModel> productModels = (response.data as List)
// .map((item) => ProductCategoryModel.fromJson(item))
// .toList();
return right(loginResponse);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
// // Print or handle the fetched data
// if (productModels.isNotEmpty)
// {
// print(
// "Data successfully fetched and parsed: ${productModels.length} categories.");
// }
// }
// return right(productModels);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
// FutureResult<String> createProduct(data) async {
// try {
// var response = await _productServices.createProduct(data);
// final String model = response.toString();
FutureResult<ProductCategory> getAllcategory(data, BuildContext context) async {
try {
var response = await _productService.getAllcategory(data);
// return right(model);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
// FutureResult<String> deleteProduct(data,id) async
// {
// try {
// var response = await _productServices.deleteProduct(data,id);
// final String model = response.toString();
ProductCategory productCategory = productCategoryFromJson(response.toString());
// return right(model);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
// final String model = response.toString();
// FutureResult<String> updateProduct(data,id) async
// {
// try {
// var response = await _productServices.updateProduct(data,id);
// 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 _productServices.uploadImage(imageFile);
// UploadImage upload=uploadImageFromJson(response.toString());
// return right(upload);
// } on DioException catch (e) {
// final error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
return right(productCategory);
} on DioException catch (e)
{
print("djhgfjdfhjg ${e}");
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
// }
FutureResult<BannerModel> getBanners(data, BuildContext context) async {
try {
var response = await _productService.getBanners(data);
BannerModel bannerresponse = bannerFromJson(response.toString());
final String model = response.toString();
return right(bannerresponse);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<String> customerLogOut(data) async {
try {
var response = await _productService.customerLogOut(data);
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);
// final VendorModel vendorModel = vendorModelFromJson(response.toString());
// if (vendorModel != null)
// {
// SharedPrefUtils.USER_NAME =
// vendorModel.firstName + " " + vendorModel.lastName;
// SharedPrefUtils.PHONE = vendorModel.phone;
// print("dkfjhdkfhkfk ${SharedPrefUtils.USER_NAME}");
// await SharedPrefUtils.setStoreId(storeId: vendorModel.storeId ?? "");
// }
// final String model = response.toString();
// return right(vendorModel);
// } on DioException catch (e) {
// var error = CustomDioExceptions.handleError(e);
// return left(error);
// }
// }
}

View File

@@ -3,25 +3,22 @@ import 'dart:convert';
import 'package:grocery_app/src/core/constant/api.dart';
import 'package:grocery_app/src/core/network_services/api_services.dart';
class ProductService extends ApiService {
Future getMe(data) async {
Future getMe(data) async {
var response = await api.get(APIURL.getMe, data: jsonEncode(data));
//response.statusCode
return response;
}
Future refresh_token(data) async
{
Future refresh_token(data) async {
var response = await api.post(APIURL.refresh_token, data: jsonEncode(data));
return response;
}
Future getAllProduct(data) async {
Future getAllProduct(data) async
{
var response = await api.get(APIURL.getAllProduct, data: jsonEncode(data));
return response;
@@ -30,5 +27,31 @@ class ProductService extends ApiService {
Future getBestDealProduct(data) async
{
var response = await api.get(APIURL.getBestDealProduct, data: jsonEncode(data));
return response;
}
Future getAllcategory(data) async
{
var response = await api.get(APIURL.getAllcategory, data: jsonEncode(data));
return response;
}
Future getBanners(data) async {
var response = await api.get(APIURL.getBanners, data: jsonEncode(data));
return response;
}
Future customerLogOut(data) async {
var response = await api.post(APIURL.customerLogOut, data: jsonEncode(data));
return response;
}
}

View File

@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:grocery_app/src/common_widget/network_image.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/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:provider/provider.dart';
class FruitVeggieDetail extends StatefulWidget {
const FruitVeggieDetail({super.key});
@@ -14,17 +16,19 @@ class FruitVeggieDetail extends StatefulWidget {
}
class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
int activeIndex = 0;
@override
void initState() {
Provider.of<ProductProvider>(context, listen: false)
.getAllcategory(context);
void changeActiveIndex(int currentActiveIndex) {
activeIndex = currentActiveIndex;
setState(() {});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
centerTitle: true,
leading: Center(
child: SizedBox(
@@ -62,175 +66,373 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
],
),
body: Row(
children: [
Container(
decoration: const BoxDecoration(color: Colors.white),
width: 100,
child: ListView.builder(
itemCount: 10,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
changeActiveIndex(index);
},
child: SizedBox(
height: 150,
child: Column(
children: [
Row(
children: [filterCategory(), productWidget()],
),
);
}
Widget productWidget() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isLoadingg) {
return Center(child: CircularProgressIndicator());
} else if (provider.products.isEmpty) {
return Center(child: Text('No products available'));
} else {
return Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: LayoutBuilder(
builder: (context, constraints) {
final itemWidth = (constraints.maxWidth - 20) / 2;
final itemHeight = itemWidth * 1.5;
return GridView.builder(
itemCount: provider.products.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: itemWidth / itemHeight,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemBuilder: (context, index) {
var product = provider.products[index];
return Container(
height: itemHeight,
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: [
Expanded(
child: Center(
child: Container(
decoration: BoxDecoration(
color: activeIndex == index ? Colors.greenAccent.withOpacity(0.1) : APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(5),
Container(
height: itemWidth *
0.6, // Adjust height for image container
width: itemWidth,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15),
),
child: Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 70,
width: 70,
imageUrl: product
.productImages!.first.url ??
"https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
backGroundColor: Colors.transparent,
),
child: AppNetworkImage(
height: 80,
width: 80,
imageUrl: 'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border),
),
),
],
),
),
Container(
width: 3,
height: 100,
color: activeIndex == index ? APPCOLOR.lightGreen : Colors.transparent,
)
const SizedBox(height: 5),
Text(
product.name ?? " ",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(
APPCOLOR.balck1A1A1A, 14),
),
const SizedBox(height: 5),
Text(
product.unit ?? " ",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(
Colors.grey.withOpacity(0.8),
12,
),
),
const SizedBox(height: 3),
Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"\$${product.discountPrice ?? " "}",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customSemiBold(
Colors.black, 12),
),
const SizedBox(width: 5),
Text(
"\$${product.basePrice ?? " "}",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context
.customMedium(
Colors.grey.withOpacity(0.8),
12,
)
.copyWith(
decoration:
TextDecoration.lineThrough,
),
),
],
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Container(
height: 40,
width: 60,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Add',
style: context.customRegular(
Colors.white, 12),
),
),
),
),
),
],
),
],
),
Text(
"Fresh Vegitables",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: activeIndex == index ? context.customExtraBold(APPCOLOR.balck1A1A1A, 14) : context.customMedium(APPCOLOR.balck1A1A1A, 14),
)
],
),
),
),
);
},
);
},
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: GridView.builder(
itemCount: 20,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2, childAspectRatio: MediaQuery.of(context).size.width / (MediaQuery.of(context).size.height / 1.1), crossAxisSpacing: 10, mainAxisSpacing: 10),
itemBuilder: (context, index) {
return Container(
height: 300,
// width: 150,
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,
width: 150,
decoration: BoxDecoration(color: APPCOLOR.bgGrey, borderRadius: BorderRadius.circular(15)),
child: const Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 70,
width: 70,
imageUrl: "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
backGroundColor: Colors.transparent),
Positioned(right: 5, top: 5, child: Icon(Icons.favorite_border))
],
),
),
Text(
"Fortune Arhar Dal (Toor Dal)",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
const SizedBox(
height: 5,
),
Text(
"500 ML",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(Colors.grey.withOpacity(0.8), 12),
),
const SizedBox(
height: 3,
),
Row(
children: [
Column(
children: [
Text(
"\$12",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customSemiBold(Colors.black, 12),
);
// Expanded(
// child: Padding(
// padding: const EdgeInsets.only(left: 10, right: 10),
// child: GridView.builder(
// itemCount: provider.products.length,
// gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
// crossAxisCount: 2,
// childAspectRatio: MediaQuery.of(context).size.width /
// (MediaQuery.of(context).size.height / 1.1),
// crossAxisSpacing: 10,
// mainAxisSpacing: 10),
// itemBuilder: (context, index) {
// return Container(
// height: MediaQuery.of(context).size.height * 0.28,
// // width: 150,
// 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,
// width: 150,
// decoration: BoxDecoration(
// color: APPCOLOR.bgGrey,
// borderRadius: BorderRadius.circular(15)),
// child: const Stack(
// alignment: Alignment.center,
// children: [
// AppNetworkImage(
// height: 70,
// width: 70,
// imageUrl:
// "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
// backGroundColor: Colors.transparent),
// Positioned(
// right: 5,
// top: 5,
// child: Icon(Icons.favorite_border))
// ],
// ),
// ),
// Text(
// "Fortune Arhar Dal (Toor Dal)",
// textAlign: TextAlign.left,
// maxLines: 2,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
// ),
// const SizedBox(
// height: 5,
// ),
// Text(
// "500 ML",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customMedium(
// Colors.grey.withOpacity(0.8), 12),
// ),
// const SizedBox(
// height: 3,
// ),
// Row(
// children: [
// Column(
// children: [
// Text(
// "\$12",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context.customSemiBold(Colors.black, 12),
// ),
// const SizedBox(
// width: 5,
// ),
// Text(
// "\$14",
// textAlign: TextAlign.left,
// maxLines: 1,
// overflow: TextOverflow.ellipsis,
// style: context
// .customMedium(
// Colors.grey.withOpacity(0.8), 12)
// .copyWith(
// decoration: TextDecoration.lineThrough,
// ),
// ),
// ],
// ),
// Expanded(
// child: Align(
// alignment: Alignment.centerRight,
// child: Container(
// height: 40,
// width: 60,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Add',
// style:
// context.customRegular(Colors.white, 12),
// )),
// ),
// ),
// )
// ],
// ),
// ],
// ),
// ),
// );
// },
// ),
// ));
}
});
}
Widget filterCategory() {
final activeIndexProvider = Provider.of<ProductProvider>(context);
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.iscategroyloading) {
return Center(child: CircularProgressIndicator());
} else if (provider.categoryList.isEmpty) {
return Center(child: Text('No products available'));
} else {
return Container(
decoration: const BoxDecoration(color: Colors.white),
width: 100,
child: ListView.builder(
itemCount: provider.categoryList.length,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
var category = provider.categoryList[index];
return InkWell(
onTap: ()
{
activeIndexProvider.setActiveIndex(index);
},
child: SizedBox(
height: 150,
child: Column(
children: [
Row(
children: [
Expanded(
child: Center(
child: Container(
decoration: BoxDecoration(
color:
activeIndexProvider.activeIndex == index
? Colors.greenAccent.withOpacity(0.1)
: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(5),
),
const SizedBox(
width: 5,
),
Text(
"\$14",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(Colors.grey.withOpacity(0.8), 12).copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Container(
height: 40,
width: 60,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Add',
style: context.customRegular(Colors.white, 12),
)),
child: AppNetworkImage(
height: 80,
width: 80,
imageUrl: category.image ??
'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
),
),
)
],
),
],
),
),
),
Container(
width: 3,
height: 100,
color: activeIndexProvider.activeIndex == index
? APPCOLOR.lightGreen
: Colors.transparent,
),
],
),
Text(
category.name,
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: activeIndexProvider.activeIndex == index
? context.customExtraBold(APPCOLOR.balck1A1A1A, 14)
: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
],
),
);
},
),
))
],
),
);
),
);
},
),
);
}
});
}
}

View File

@@ -1,10 +1,16 @@
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.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/bestdeal/bestdeal_screen.dart';
import 'package:grocery_app/src/ui/fruitvegidetail/fruit_veggie_detail.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/extensions/extensions.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';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@@ -15,6 +21,19 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
Provider.of<ProductProvider>(context, listen: false).getBanners(context);
Provider.of<ProductProvider>(context, listen: false)
.gettAllProduct(context);
Provider.of<ProductProvider>(context, listen: false)
.getBestDealProduct(context);
Provider.of<ProductProvider>(context, listen: false)
.getAllcategory(context);
}
@override
Widget build(BuildContext context) {
return SafeArea(
@@ -46,7 +65,8 @@ class _HomeScreenState extends State<HomeScreen> {
children: [
Text(
"Home",
style: context.customMedium(APPCOLOR.black333333, 18),
style: context.customMedium(
APPCOLOR.black333333, 18),
),
const SizedBox(
width: 5,
@@ -92,9 +112,11 @@ class _HomeScreenState extends State<HomeScreen> {
fillColor: Colors.transparent,
prefixIcon: Icon(MdiIcons.magnify),
hintText: 'Search',
hintStyle: context.customRegular(APPCOLOR.grey666666, 18),
hintStyle:
context.customRegular(APPCOLOR.grey666666, 18),
isCollapsed: true,
contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
contentPadding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 10),
),
),
),
@@ -132,11 +154,13 @@ class _HomeScreenState extends State<HomeScreen> {
),
InkWell(
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return const FruitVeggieDetail();
},
));
// Navigator.of(context).push(MaterialPageRoute(
// builder: (context) {
// return const FruitVeggieDetail();
// },
// ));
context.push(MyRoutes.FRUITVEGGIEDETAIL);
},
child: Text(
"See All",
@@ -148,98 +172,11 @@ class _HomeScreenState extends State<HomeScreen> {
const SizedBox(
height: 15,
),
GridView.builder(
shrinkWrap: true,
itemCount: 8,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: MediaQuery.of(context).size.width / (MediaQuery.of(context).size.height / 1.2),
),
itemBuilder: (context, index)
{
return InkWell(
onTap: () {},
child: SizedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
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,
),
),
const SizedBox(
height: 10,
),
Text(
"Vegitables and Fruits",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
)
],
),
),
);
},
),
categoriesProduct(),
const SizedBox(
height: 15,
),
Container(
height: 180,
decoration: BoxDecoration(color: Colors.greenAccent.withOpacity(0.1), borderRadius: BorderRadius.circular(15)),
child: Stack(
children: [
Positioned(
top: 15,
left: 15,
child: SizedBox(
width: 200,
child: Text(
"World Food Festival, Bring the world to your Kitchen!",
style: context.customExtraBold(Colors.black, 18),
))),
Positioned(
bottom: 15,
left: 15,
child: Container(
height: 40,
width: 100,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Shop now',
style: context.customRegular(Colors.white, 14),
)),
),
),
const Positioned(
right: 15,
bottom: 15,
child: AppNetworkImage(
height: 130,
width: 150,
imageUrl: 'https://e7.pngegg.com/pngimages/742/816/png-clipart-coca-cola-can-illustration-coca-cola-soft-drink-surge-pepsi-coke-sweetness-cola-thumbnail.png',
backGroundColor: Colors.transparent))
],
),
),
bannerview(),
const SizedBox(
height: 15,
),
@@ -270,119 +207,7 @@ class _HomeScreenState extends State<HomeScreen> {
const SizedBox(
height: 15,
),
SizedBox(
height: 222,
child: ListView.builder(
itemCount: 5,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),
child: Container(
height: 215,
width: 150,
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,
width: 150,
decoration: BoxDecoration(color: APPCOLOR.bgGrey, borderRadius: BorderRadius.circular(15)),
child: const Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 70,
width: 70,
imageUrl: "https://5.imimg.com/data5/SELLER/Default/2024/2/385126988/OL/DA/VW/8627346/1l-fortune-sunflower-oil.jpg",
backGroundColor: Colors.transparent),
Positioned(right: 5, top: 5, child: Icon(Icons.favorite_border))
],
),
),
Text(
"Fortune Arhar Dal (Toor Dal)",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
const SizedBox(
height: 5,
),
Text(
"500 ML",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(Colors.grey.withOpacity(0.8), 12),
),
const SizedBox(
height: 3,
),
Row(
children: [
Expanded(
child: Row(
children: [
Text(
"\$12",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customSemiBold(Colors.black, 12),
),
const SizedBox(
width: 5,
),
Text(
"\$14",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(Colors.grey.withOpacity(0.8), 12).copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
)),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: Container(
height: 30,
width: 50,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Add',
style: context.customRegular(Colors.white, 12),
)),
),
),
)
],
),
],
),
),
),
);
},
),
),
bestDeal(),
const SizedBox(
height: 20,
),
@@ -394,9 +219,371 @@ class _HomeScreenState extends State<HomeScreen> {
);
}
@override
void initState() {
// SizeConfig().init(context);
super.initState();
// Widget bannerview() {
// return Consumer<ProductProvider>(builder: (context, provider, child)
// {
// if (provider.isBannerLoading) {
// return Center(child: CircularProgressIndicator());
// } else if (provider.banner.isEmpty) {
// return Center(child: Text('No products available'));
// } else {
// return
// Container(
// height: 180,
// decoration: BoxDecoration(
// color: Colors.greenAccent.withOpacity(0.1),
// borderRadius: BorderRadius.circular(15)),
// child: Stack(
// children: [
// Positioned(
// top: 15,
// left: 15,
// child: SizedBox(
// width: 200,
// child: Text(
// "World Food Festival, Bring the world to your Kitchen!",
// style: context.customExtraBold(Colors.black, 18),
// ))),
// Positioned(
// bottom: 15,
// left: 15,
// child: Container(
// height: 40,
// width: 100,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// borderRadius: BorderRadius.circular(5),
// ),
// child: Center(
// child: Text(
// 'Shop now',
// style: context.customRegular(Colors.white, 14),
// )),
// ),
// ),
// const Positioned(
// right: 15,
// bottom: 15,
// child: AppNetworkImage(
// height: 130,
// width: 150,
// imageUrl:
// 'https://e7.pngegg.com/pngimages/742/816/png-clipart-coca-cola-can-illustration-coca-cola-soft-drink-surge-pepsi-coke-sweetness-cola-thumbnail.png',
// backGroundColor: Colors.transparent))
// ],
// ),
// );
// }
// });
// }
Widget bestDeal() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isBestdealingloading) {
return Center(child: CircularProgressIndicator());
} else if (provider.bestdeal.isEmpty) {
return Center(child: Text('No products available'));
} else {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.28,
child: ListView.builder(
itemCount: provider.bestdeal.length,
scrollDirection: Axis.horizontal,
itemBuilder: (context, index) {
var bestdealproduct = provider.bestdeal[index];
double cardWidth =
MediaQuery.of(context).size.width * 0.4; // Dynamic width
return Padding(
padding: const EdgeInsets.only(right: 10, bottom: 5, top: 5),
child: Container(
width: cardWidth,
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: [
Center(
child: Container(
height: MediaQuery.of(context).size.height * 0.12,
width: cardWidth * 0.9,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15),
),
child: Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height:
MediaQuery.of(context).size.height * 0.08,
width: cardWidth * 0.7,
imageUrl: bestdealproduct
.productImages?.first?.url ??
"",
backGroundColor: Colors.transparent,
),
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border),
),
],
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.01,
),
Text(
bestdealproduct.name ?? "",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
),
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,
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
),
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),
),
),
),
),
],
),
],
),
),
),
);
},
),
);
}
});
}
Widget bannerview() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isBannerLoading) {
return Center(child: CircularProgressIndicator());
} else if (provider.banner.isEmpty) {
return Center(child: Text('No products available'));
} else {
return CarouselSlider(
options: CarouselOptions(
height: 180,
autoPlay: true,
enlargeCenterPage: true,
viewportFraction: 1,
aspectRatio: 16 / 9,
initialPage: 0,
enableInfiniteScroll: true,
reverse: false,
autoPlayInterval: Duration(seconds: 3),
autoPlayAnimationDuration: Duration(milliseconds: 800),
autoPlayCurve: Curves.fastOutSlowIn,
enlargeFactor: 0.3,
//aspectRatio: 16 / 9,
//viewportFraction: 0.9,
),
items: provider.banner.map((banner) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
// margin: const EdgeInsets.symmetric(horizontal: 8.0),
decoration: BoxDecoration(
color: Colors.greenAccent.withOpacity(0.1),
borderRadius: BorderRadius.circular(15),
),
child: Stack(
children: [
Positioned(
top: 15,
left: 15,
child: SizedBox(
width: 200,
child: Text(
banner.altText ?? "Special Event",
style: context.customExtraBold(Colors.black, 18),
),
),
),
Positioned(
bottom: 15,
left: 15,
child: GestureDetector(
onTap: () {
// Add your navigation or shop action here
},
child: Container(
height: 40,
width: 100,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(5),
),
child: Center(
child: Text(
'Shop now',
style: context.customRegular(Colors.white, 14),
),
),
),
),
),
Positioned(
right: 15,
bottom: 15,
child: AppNetworkImage(
height: 130,
width: 150,
imageUrl: banner.imageUrl ??
'https://e7.pngegg.com/pngimages/742/816/png-clipart-coca-cola-can-illustration-coca-cola-soft-drink-surge-pepsi-coke-sweetness-cola-thumbnail.png',
backGroundColor: Colors.transparent,
),
),
],
),
);
},
);
}).toList(),
);
}
});
}
Widget categoriesProduct() {
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isLoadingg) {
return Center(child: CircularProgressIndicator());
} else if (provider.products.isEmpty) {
return Center(child: Text('No products available'));
} else {
return GridView.builder(
shrinkWrap: true,
itemCount: provider.products.length,
physics: const NeverScrollableScrollPhysics(),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
crossAxisSpacing: 5,
mainAxisSpacing: 5,
childAspectRatio: MediaQuery.of(context).size.width /
(MediaQuery.of(context).size.height / 1.2),
),
itemBuilder: (context, index) {
var product = provider.products[index];
return InkWell(
onTap: () {},
child: SizedBox(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(5),
),
child: AppNetworkImage(
height: 80,
width: 80,
imageUrl: product.productImages!.first.url,
//'https://i.pinimg.com/originals/a5/f3/5f/a5f35fb23e942809da3df91b23718e8d.png',
backGroundColor: APPCOLOR.bgGrey,
radius: 10,
),
),
const SizedBox(
height: 10,
),
Text(
"Vegitables and Fruits",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 14),
)
],
),
),
);
},
);
}
});
}
}

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/ui/card_checkout/card_checkout_screen.dart';
import 'package:grocery_app/src/ui/edit_profile/edit_profile_screen.dart';
import 'package:grocery_app/src/ui/message/message_screen.dart';
@@ -9,6 +10,7 @@ import 'package:grocery_app/src/ui/static_page/static_page_screen.dart';
import 'package:grocery_app/utils/constants/color_constant.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';
class ProfileScreen extends StatefulWidget {
const ProfileScreen({super.key});
@@ -32,7 +34,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
pinned: true,
backgroundColor: Colors.white,
leading: const SizedBox(),
flexibleSpace: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
flexibleSpace: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
top = constraints.biggest.height;
return FlexibleSpaceBar(
@@ -44,7 +47,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
top > 100
? Text(
"My Profile",
style: context.customExtraBold(Colors.white, 14),
style:
context.customExtraBold(Colors.white, 14),
)
: const SizedBox(),
@@ -63,7 +67,8 @@ class _ProfileScreenState extends State<ProfileScreen> {
AppNetworkImage(
height: top < 150 ? 30 : 50,
width: top < 150 ? 30 : 50,
imageUrl: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdQLwDqDwd2JfzifvfBTFT8I7iKFFevcedYg&s",
imageUrl:
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdQLwDqDwd2JfzifvfBTFT8I7iKFFevcedYg&s",
radius: 90,
backGroundColor: Colors.white,
boxFit: BoxFit.fill,
@@ -75,7 +80,12 @@ class _ProfileScreenState extends State<ProfileScreen> {
child: Container(
height: 18,
width: 18,
decoration: BoxDecoration(color: APPCOLOR.lightGreen, border: Border.all(color: Colors.white), borderRadius: BorderRadius.circular(5)),
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
border: Border.all(
color: Colors.white),
borderRadius:
BorderRadius.circular(5)),
child: Center(
child: Icon(
MdiIcons.pencil,
@@ -97,11 +107,15 @@ class _ProfileScreenState extends State<ProfileScreen> {
children: [
Text(
"Smith Mate",
style: context.customExtraBold(top < 100 ? Colors.black : Colors.white, 14),
style: context.customExtraBold(
top < 100 ? Colors.black : Colors.white,
14),
),
Text(
'smithmate@example.com',
style: context.customRegular(top < 100 ? Colors.black : Colors.white, 10),
style: context.customRegular(
top < 100 ? Colors.black : Colors.white,
10),
)
],
),
@@ -114,7 +128,11 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
background: Container(
height: 200,
decoration: BoxDecoration(color: APPCOLOR.lightGreen, borderRadius: const BorderRadius.only(bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30))),
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
));
}),
),
@@ -122,6 +140,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
},
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
@@ -238,27 +257,39 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
),
),
Container(
margin: const EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 10),
height: 50,
width: MediaQuery.sizeOf(context).width,
decoration: BoxDecoration(color: APPCOLOR.lightGreen, borderRadius: BorderRadius.circular(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
MdiIcons.logout,
color: Colors.white,
),
const SizedBox(
width: 10,
),
Text(
"Logout",
style: context.customMedium(Colors.white, 16),
),
],
InkWell(
onTap: ()
{
print("fjnghkjfjghj");
Provider.of<ProductProvider>(context, listen: false)
.customerLogOut(context);
},
child: Container(
margin: const EdgeInsets.only(
left: 15, right: 15, top: 10, bottom: 10),
height: 50,
width: MediaQuery.sizeOf(context).width,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: BorderRadius.circular(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(
MdiIcons.logout,
color: Colors.white,
),
const SizedBox(
width: 10,
),
Text(
"Logout",
style: context.customMedium(Colors.white, 16),
),
],
),
),
),
],