This commit is contained in:
2025-01-28 19:05:19 +05:30
parent b9cd807bbc
commit 3121e0ee36
24 changed files with 1347 additions and 1446 deletions

View File

@@ -10,6 +10,8 @@ class APIURL {
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 addToWish = "${BASE_URL}carts/wishlist/items";
static const String addToCart = "${BASE_URL}carts/items";

View File

@@ -1,19 +1,19 @@
// To parse this JSON data, do
//
// final registrationResponse = registrationResponseFromJson(jsonString?);
// final registrationResponse = registrationResponseFromJson(jsondynamic?);
import 'dart:convert';
RegistrationResponse registrationResponseFromJson(String str) =>
RegistrationResponse registrationResponseFromJson(dynamic str) =>
RegistrationResponse.fromJson(json.decode(str));
String? registrationResponseToJson(RegistrationResponse data) =>
dynamic? registrationResponseToJson(RegistrationResponse data) =>
json.encode(data.toJson());
class RegistrationResponse {
Customer? customer;
String? accessToken;
String? refreshToken;
dynamic? accessToken;
dynamic? refreshToken;
RegistrationResponse({
this.customer,
@@ -21,14 +21,14 @@ class RegistrationResponse {
this.refreshToken,
});
factory RegistrationResponse.fromJson(Map<String?, dynamic> json) =>
factory RegistrationResponse.fromJson(Map<dynamic?, dynamic> json) =>
RegistrationResponse(
customer: Customer.fromJson(json["customer"]),
accessToken: json["access_token"],
refreshToken: json["refresh_token"],
);
Map<String?, dynamic> toJson() => {
Map<dynamic?, dynamic> toJson() => {
"customer": customer!.toJson(),
"access_token": accessToken,
"refresh_token": refreshToken,
@@ -36,15 +36,15 @@ class RegistrationResponse {
}
class Customer {
String? id;
String? email;
String? firstName;
String? lastName;
dynamic? id;
dynamic? email;
dynamic? firstName;
dynamic? lastName;
dynamic name;
dynamic img;
String? authType;
String? role;
String? phone;
dynamic? authType;
dynamic? role;
dynamic? phone;
dynamic password;
bool? isPhoneVerified;
dynamic vendorType;
@@ -80,7 +80,7 @@ class Customer {
this.resetTokenExpiresAt,
});
factory Customer.fromJson(Map<String?, dynamic> json) => Customer(
factory Customer.fromJson(Map<dynamic?, dynamic> json) => Customer(
id: json["id"],
email: json["email"],
firstName: json["firstName"],
@@ -103,7 +103,7 @@ class Customer {
resetTokenExpiresAt: json["resetTokenExpiresAt"],
);
Map<String?, dynamic> toJson() => {
Map<dynamic?, dynamic> toJson() => {
"id": id,
"email": email,
"firstName": firstName,

View File

@@ -143,7 +143,8 @@ class AuthProvider extends ChangeNotifier {
);
return false; // Login failed
},
(response) {
(response)
{
// Login success
context.showLoader(show: false);
ScaffoldMessenger.of(context).showSnackBar(

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:grocery_app/src/core/network_services/service_locator.dart';
import 'package:grocery_app/src/core/routes/routes.dart';
import 'package:grocery_app/src/data/allProduct_model.dart';
@@ -16,10 +17,12 @@ class ProductProvider extends ChangeNotifier {
List<Product> products = [];
Future<void> gettAllProduct(BuildContext context) async {
Future<void> gettAllProduct(BuildContext context, String id) async {
var data = {};
var result = await _homeRepo.getAllProduct(data, context);
print("skdjhfgkf ${id}");
var result = await _homeRepo.getAllProduct(data, context, id);
return result.fold(
(error) {
isLoadingg = false;
@@ -63,7 +66,7 @@ class ProductProvider extends ChangeNotifier {
var result = await _homeRepo.getAllcategory(data, context);
return result.fold(
(error) {
print("djhgfjdfhjg ${error}");
print("djhgfjdfhjg ${error}");
iscategroyloading = false;
notifyListeners();
},
@@ -152,4 +155,76 @@ class ProductProvider extends ChangeNotifier {
_activeIndex = index;
notifyListeners();
}
// Mock API call
Future<bool> addToWish(BuildContext context, String productId) async {
//context.showLoader(show: true);
var data = {
"productId": productId,
};
try {
var result = await _homeRepo.addToWish(data);
return result.fold(
(error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(error.message),
backgroundColor: Colors.red,
),
);
return false;
},
(response) {
Fluttertoast.showToast(
msg: "Wishlist updated successfully!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 14.0,
);
return true;
},
);
} catch (e) {
return false;
}
}
Set<String> wishlist = {}; // To store product IDs in the wishlist
// Function to add/remove product from wishlist
Future<void> toggleWishlist(BuildContext context, String productId) async {
try {
if (wishlist.contains(productId)) {
wishlist.remove(productId);
} else {
// Call the API to add to wishlist
var result = await addToWish(context, productId);
wishlist.add(productId); // Add the product ID to the wishlist
}
notifyListeners(); // Notify listeners to update the UI
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Something went wrong. Please try again."),
backgroundColor: Colors.red,
),
);
}
}
}

View File

@@ -89,20 +89,22 @@ class AuthRepo {
// }
// }
FutureResult<String> customerRegister(data) async {
FutureResult<RegistrationResponse> customerRegister(data) async {
try {
var response = await _authServices.userRegister(data);
RegistrationResponse registrationResponse =
registrationResponseFromJson(response.toString());
await SharedPrefUtils.setToken(
authToken: registrationResponse.accessToken ?? "");
if (response.statCode) {
print("dsfklgjkfgbfgkfdgjkhkfdjg");
}
print("dsfklgjkfgbfgkfdgjkhkfdjg ${registrationResponse.accessToken}");
// if (response.statCode) {
// print("dsfklgjkfgbfgkfdgjkhkfdjg");
// }
final String model = response.toString();
return right(model);
return right(registrationResponse);
} on DioException catch (e) {
var error = CustomDioExceptions.handleError(e);
return left(error);

View File

@@ -14,9 +14,10 @@ class ProductRepo {
ProductRepo(this._productService);
FutureResult<AllProductModel> getAllProduct(data, BuildContext context) async {
FutureResult<AllProductModel> getAllProduct(
data, BuildContext context, id) async {
try {
var response = await _productService.getAllProduct(data);
var response = await _productService.getAllProduct(data, id);
AllProductModel loginResponse =
allProductModelFromJson(response.toString());
@@ -30,7 +31,8 @@ class ProductRepo {
}
}
FutureResult<BestDealProduct> getBestDealProduct(data, BuildContext context) async {
FutureResult<BestDealProduct> getBestDealProduct(
data, BuildContext context) async {
try {
var response = await _productService.getBestDealProduct(data);
@@ -46,16 +48,48 @@ class ProductRepo {
}
}
FutureResult<ProductCategory> getAllcategory(data, BuildContext context) async {
FutureResult<ProductCategory> getAllcategory(
data, BuildContext context) async {
try {
var response = await _productService.getAllcategory(data);
ProductCategory productCategory = productCategoryFromJson(response.toString());
ProductCategory productCategory =
productCategoryFromJson(response.toString());
// final String model = response.toString();
// final String model = response.toString();
return right(productCategory);
} on DioException catch (e) {
print("djhgfjdfhjg ${e}");
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<String> addToWish(data) async
{
try {
var response = await _productService.addToWish(data);
final String model = response.toString();
return right(model);
} on DioException catch (e)
{
print("djhgfjdfhjg ${e}");
var error = CustomDioExceptions.handleError(e);
return left(error);
}
}
FutureResult<String> addToCart(data) async
{
try {
var response = await _productService.addToCart(data);
final String model = response.toString();
return right(model);
} on DioException catch (e)
{
print("djhgfjdfhjg ${e}");

View File

@@ -17,31 +17,49 @@ class ProductService extends ApiService {
return response;
}
Future getAllProduct(data) async
{
var response = await api.get(APIURL.getAllProduct, data: jsonEncode(data));
Future getAllProduct(data, id) async {
var response;
if (id.isEmpty) {
response =
await api.get(APIURL.getAllProduct, data: jsonEncode(data));
}
else{
response = await api.get(APIURL.getAllProduct+ id, data: jsonEncode(data));
}
return response;
}
Future getBestDealProduct(data) async
{
var response = await api.get(APIURL.getBestDealProduct, data: jsonEncode(data));
Future getBestDealProduct(data) async {
var response =
await api.get(APIURL.getBestDealProduct, data: jsonEncode(data));
return response;
}
Future getAllcategory(data) async
{
Future getAllcategory(data) async {
var response = await api.get(APIURL.getAllcategory, data: jsonEncode(data));
return response;
}
Future addToWish(data) async {
var response = await api.post(APIURL.addToWish, data: jsonEncode(data));
return response;
}
Future addToCart(data) async {
var response = await api.post(APIURL.addToCart, data: jsonEncode(data));
return response;
}
Future getBanners(data) async {
var response = await api.get(APIURL.getBanners, data: jsonEncode(data));
@@ -50,7 +68,8 @@ class ProductService extends ApiService {
}
Future customerLogOut(data) async {
var response = await api.post(APIURL.customerLogOut, data: jsonEncode(data));
var response =
await api.post(APIURL.customerLogOut, data: jsonEncode(data));
return response;
}

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 BestDealScreen extends StatefulWidget {
const BestDealScreen({super.key});
@@ -17,221 +19,259 @@ class _BestDealScreenState extends State<BestDealScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
leading: Center(
child: SizedBox(
height: 20,
width: 20,
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: SvgPicture.asset(
APPASSETS.back,
height: 20,
width: 20,
)),
),
),
title: const Text(
"Best Deal",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
actions: [
InkWell(
onTap: () {},
child: Icon(
MdiIcons.magnify,
size: 35,
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
leading: Center(
child: SizedBox(
height: 20,
width: 20,
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: SvgPicture.asset(
APPASSETS.back,
height: 20,
width: 20,
)),
),
)
],
),
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(
),
title: const Text(
"Best Deal",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
),
),
actions: [
InkWell(
onTap: () {},
child: Icon(
MdiIcons.magnify,
size: 35,
),
)
],
),
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,
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,
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 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,
),
],
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: const EdgeInsets.all(15),
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(
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: 160,
width: MediaQuery.sizeOf(context).width,
// width: 150,
decoration: BoxDecoration(color: APPCOLOR.bgGrey, borderRadius: BorderRadius.circular(15)),
child: const Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 150,
width: 140,
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))
],
body: itemBestdeal());
}
Widget itemBestdeal() {
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 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),
),
),
Text(
"Fortune Arhar Dal (Toor Dal)",
textAlign: TextAlign.left,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: context.customMedium(APPCOLOR.balck1A1A1A, 16),
),
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(
]),
child: Padding(
padding: const EdgeInsets.all(5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 160,
width: MediaQuery.sizeOf(context).width,
// width: 150,
decoration: BoxDecoration(
color: APPCOLOR.bgGrey,
borderRadius: BorderRadius.circular(15)),
child: Stack(
alignment: Alignment.center,
children: [
AppNetworkImage(
height: 150,
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,
),
Row(
children: [
Row(
children: [
Text(
"\$12",
"\$${bestdealproduct.discountPrice ?? ""} ",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customSemiBold(Colors.black, 16),
),
const SizedBox(
width: 5,
style: context.customSemiBold(Colors.black, 12),
),
Text(
"\$14",
"\$${bestdealproduct.basePrice ?? ""}",
textAlign: TextAlign.left,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.customMedium(Colors.grey.withOpacity(0.8), 16).copyWith(
style: context
.customMedium(
Colors.grey.withOpacity(0.8),
12,
)
.copyWith(
decoration: TextDecoration.lineThrough,
),
),
],
),
),
Expanded(
child: Align(
const Spacer(),
Align(
alignment: Alignment.centerRight,
child: Container(
height: 40,
width: 60,
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: Text(
'Add',
style:
context.customRegular(Colors.white, 12),
),
),
),
),
)
],
),
],
],
),
],
),
),
),
);
},
),
),
);
);
},
),
);
}
});
}
}

View File

@@ -3,6 +3,7 @@
import 'package:flutter/material.dart';
import 'package:grocery_app/src/ui/cart/cartview_screen.dart';
import 'package:grocery_app/src/ui/favourite/favourite_screen.dart';
import 'package:grocery_app/src/ui/header.dart';
import 'package:grocery_app/src/ui/home/home_screen.dart';
import 'package:grocery_app/src/ui/profilepage/profile_screen.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
@@ -47,10 +48,12 @@ class _BottomBarState extends State<BottomBarWidget> {
SizeConfig().init(context);
return Scaffold(
body: PageView(
controller: bottomWidgetPageController,
physics: const NeverScrollableScrollPhysics(),
children: <Widget>[
HomeScreen(),
FavouriteScreen(),
Mycart(),

View File

@@ -113,7 +113,7 @@ class _EnterFullNameScreenState extends State<EnterFullNameScreen> {
onTap: () async {
if (_formKey.currentState?.validate() ?? false) {
final success = await pageNotifier.customerRegister(context);
print("dshfgjkdfjgh ${success}");
if (success) {
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
}

View File

@@ -1,8 +1,10 @@
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/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';
class FavouriteScreen extends StatefulWidget {
@override
@@ -37,117 +39,126 @@ class _FavouriteScreenState extends State<FavouriteScreen>
@override
Widget build(BuildContext context) {
return Column(
children: [
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,
return SafeArea(
child: Scaffold(
body: Padding(
padding: context.bodyAllPadding.copyWith(
top: 0,
),
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,
),
),
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(_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,
);
_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(
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,
)
],
),
),
child: child,
),
);
},
child: Divider(),
);
},
);
},
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,
),
child: child,
),
);
},
child: Divider(),
);
},
),
),
// Padding(
// padding:
// const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 78),
// child: NectarButton(
// onPressed: () {},
// text: 'Add All To Cart',
// ),
// ),
],
),
),
// Padding(
// padding:
// const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 78),
// child: NectarButton(
// onPressed: () {},
// text: 'Add All To Cart',
// ),
// ),
],
),
);
}
}

View File

@@ -71,12 +71,19 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
);
}
Widget productWidget() {
Widget productWidget()
{
return Consumer<ProductProvider>(builder: (context, provider, child) {
if (provider.isLoadingg) {
return Center(child: CircularProgressIndicator());
return Padding(
padding: const EdgeInsets.only(left: 120),
child: CircularProgressIndicator(),
);
} else if (provider.products.isEmpty) {
return Center(child: Text('No products available'));
return Padding(
padding: const EdgeInsets.only(left: 80),
child: Center(child: Text('No products available')),
);
} else {
return Expanded(
child: Padding(
@@ -225,136 +232,6 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
),
),
);
// 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),
// )),
// ),
// ),
// )
// ],
// ),
// ],
// ),
// ),
// );
// },
// ),
// ));
}
});
}
@@ -376,10 +253,11 @@ class _FruitVeggieDetailState extends State<FruitVeggieDetail> {
itemBuilder: (context, index) {
var category = provider.categoryList[index];
return InkWell(
onTap: ()
{
onTap: () {
provider.isLoadingg = true;
provider.gettAllProduct(context, "/category/${category.id}");
activeIndexProvider.setActiveIndex(index);
},
},
child: SizedBox(
height: 150,
child: Column(

60
lib/src/ui/header.dart Normal file
View File

@@ -0,0 +1,60 @@
import 'package:flutter/material.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';
class Header extends StatelessWidget {
const Header({super.key});
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
MdiIcons.mapMarkerOutline,
color: APPCOLOR.appGreen,
size: 30,
),
const SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"Home",
style: context.customMedium(APPCOLOR.black333333, 18),
),
const SizedBox(
width: 5,
),
Icon(
MdiIcons.chevronDown,
color: APPCOLOR.black333333,
size: 30,
)
],
),
Text(
"639| Elgin St. Celina, Delaware 10299",
style: context.customMedium(APPCOLOR.grey666666, 14),
),
],
)),
const SizedBox(
width: 10,
),
Icon(
MdiIcons.shoppingOutline,
color: APPCOLOR.balck1A1A1A,
size: 30,
),
],
);
}
}

View File

@@ -6,7 +6,9 @@ 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/src/ui/header.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/extensions.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
@@ -26,8 +28,7 @@ class _HomeScreenState extends State<HomeScreen> {
Provider.of<ProductProvider>(context, listen: false).getBanners(context);
Provider.of<ProductProvider>(context, listen: false)
.gettAllProduct(context);
.gettAllProduct(context, "");
Provider.of<ProductProvider>(context, listen: false)
.getBestDealProduct(context);
Provider.of<ProductProvider>(context, listen: false)
@@ -45,55 +46,7 @@ class _HomeScreenState extends State<HomeScreen> {
child: SingleChildScrollView(
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
MdiIcons.mapMarkerOutline,
color: APPCOLOR.appGreen,
size: 30,
),
const SizedBox(
width: 10,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"Home",
style: context.customMedium(
APPCOLOR.black333333, 18),
),
const SizedBox(
width: 5,
),
Icon(
MdiIcons.chevronDown,
color: APPCOLOR.black333333,
size: 30,
)
],
),
Text(
"639| Elgin St. Celina, Delaware 10299",
style: context.customMedium(APPCOLOR.grey666666, 14),
),
],
)),
const SizedBox(
width: 10,
),
Icon(
MdiIcons.shoppingOutline,
color: APPCOLOR.balck1A1A1A,
size: 30,
),
],
),
Header(),
const SizedBox(
height: 15,
),
@@ -219,64 +172,6 @@ class _HomeScreenState extends State<HomeScreen> {
);
}
// 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) {
@@ -337,7 +232,28 @@ class _HomeScreenState extends State<HomeScreen> {
Positioned(
right: 5,
top: 5,
child: Icon(Icons.favorite_border),
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,
),
),
),
],
),

View File

@@ -1,135 +1,17 @@
// // import 'package:flutter/material.dart';
// // import 'package:google_maps_flutter/google_maps_flutter.dart';
// // import 'package:geolocator/geolocator.dart';
// // import 'package:geocoding/geocoding.dart';
import 'dart:convert';
// // class MapScreen extends StatefulWidget {
// // @override
// // _MapScreenState createState() => _MapScreenState();
// // }
// // class _MapScreenState extends State<MapScreen> {
// // late GoogleMapController mapController;
// // LatLng _selectedLocation = LatLng(20.5937, 78.9629); // Default: India
// // String _address = "Select a location";
// // String _pincode = "";
// // @override
// // void initState() {
// // super.initState();
// // _determinePosition();
// // }
// // // Get current location
// // Future<void> _determinePosition() async {
// // LocationPermission permission = await Geolocator.requestPermission();
// // if (permission == LocationPermission.denied) {
// // return;
// // }
// // Position position = await Geolocator.getCurrentPosition();
// // setState(() {
// // _selectedLocation = LatLng(position.latitude, position.longitude);
// // });
// // _getAddressFromLatLng(position.latitude, position.longitude);
// // }
// // // Get Address from LatLng
// // Future<void> _getAddressFromLatLng(double lat, double lng) async {
// // try {
// // List<Placemark> placemarks = await placemarkFromCoordinates(lat, lng);
// // Placemark place = placemarks[0];
// // setState(() {
// // _address =
// // "${place.street}, ${place.locality}, ${place.administrativeArea}";
// // _pincode = place.postalCode ?? "";
// // });
// // } catch (e) {
// // print(e);
// // }
// // }
// // // On map tapped
// // void _onMapTapped(LatLng tappedPoint)
// // {
// // setState(()
// // {
// // _selectedLocation = tappedPoint;
// // });
// // _getAddressFromLatLng(tappedPoint.latitude, tappedPoint.longitude);
// // }
// // @override
// // Widget build(BuildContext context) {
// // return Scaffold(
// // appBar: AppBar(title: Text("Pick Location")),
// // body: Column(
// // children: [
// // Expanded(
// // child: GoogleMap(
// // initialCameraPosition: CameraPosition(
// // target: _selectedLocation,
// // zoom: 5,
// // ),
// // onMapCreated: (controller) {
// // mapController = controller;
// // },
// // markers: {
// // Marker(
// // markerId: MarkerId("selectedLocation"),
// // position: _selectedLocation,
// // )
// // },
// // onTap: _onMapTapped,
// // ),
// // ),
// // Container(
// // padding: EdgeInsets.all(16),
// // decoration: BoxDecoration(
// // color: Colors.white,
// // boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)],
// // ),
// // child: Column(
// // crossAxisAlignment: CrossAxisAlignment.start,
// // children: [
// // Text("Selected Address:",
// // style: TextStyle(fontWeight: FontWeight.bold)),
// // SizedBox(height: 5),
// // Text(_address, style: TextStyle(fontSize: 16)),
// // SizedBox(height: 10),
// // TextField(
// // decoration: InputDecoration(labelText: "Enter Pincode"),
// // onChanged: (value) {
// // setState(()
// // {
// // _pincode = value;
// // });
// // },
// // ),
// // SizedBox(height: 10),
// // ElevatedButton(
// // onPressed: ()
// // {
// // Navigator.pop(context,
// // {
// // "location": _selectedLocation,
// // "address": _address,
// // "pincode": _pincode
// // });
// // },
// // child: Text("Confirm Location"),
// // ),
// // ],
// // ),
// // ),
// // ],
// // ),
// // );
// // }
// // }
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.dart';
import 'package:geocoding/geocoding.dart';
import 'package:grocery_app/utils/constants/color_constant.dart';
import 'package:grocery_app/utils/extensions/uicontext.dart';
import 'package:http/http.dart' as http;
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
const String googleApiKey = "AIzaSyAi3_Dls63iGs7Nccgdm-4FkS0rhT03-4U";
class MapScreen extends StatefulWidget {
@override
@@ -138,10 +20,15 @@ class MapScreen extends StatefulWidget {
class _MapScreenState extends State<MapScreen> {
late GoogleMapController mapController;
LatLng _selectedLocation = LatLng(20.5937, 78.9629); // Default: India
String _address = "Fetching current location...";
String _pincode = "";
LatLng _selectedLocation = LatLng(20.5937, 78.9629);
TextEditingController _pincodeController = TextEditingController();
TextEditingController _fullNameController = TextEditingController();
TextEditingController _PhoneNumberController = TextEditingController();
TextEditingController _addressTypeController = TextEditingController();
TextEditingController _HouseNoController = TextEditingController();
TextEditingController _RoadController = TextEditingController();
TextEditingController _AlterNativeNumberController = TextEditingController();
@override
void initState() {
@@ -149,7 +36,6 @@ class _MapScreenState extends State<MapScreen> {
_determinePosition();
}
// Get current location
Future<void> _determinePosition() async {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
@@ -162,7 +48,7 @@ class _MapScreenState extends State<MapScreen> {
}
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
desiredAccuracy: LocationAccuracy.high,
);
LatLng currentLatLng = LatLng(position.latitude, position.longitude);
@@ -173,22 +59,59 @@ class _MapScreenState extends State<MapScreen> {
_getAddressFromLatLng(position.latitude, position.longitude);
}
// Get Address from LatLng
Future<void> _getAddressFromLatLng(double lat, double lng) async {
try {
List<Placemark> placemarks = await placemarkFromCoordinates(lat, lng);
Placemark place = placemarks.first;
setState(() {
_address =
"${place.street}, ${place.locality}, ${place.administrativeArea}";
_pincode = place.postalCode ?? "";
_pincodeController.text = _pincode;
final String url =
"https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=$googleApiKey";
print(
"jhsjhdfjdsgf ${place.street}, ${place.locality}, ${place.administrativeArea} ${place.postalCode} ${place.subLocality} ${place.name} ${place.subAdministrativeArea}");
});
try {
final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) {
final data = json.decode(response.body);
if (data["status"] == "OK") {
var result = data["results"][0]; // First result is most accurate
_RoadController.text = result["formatted_address"];
List components = result["address_components"];
String roadName = "";
String colony = "";
String buildingName = "";
String pincode = "";
for (var component in components) {
List types = component["types"];
if (types.contains("route")) {
roadName = component["long_name"]; // Road Name
} else if (types.contains("sublocality_level_1") ||
types.contains("locality")) {
colony = component["long_name"]; // Colony Name
} else if (types.contains("premise") ||
types.contains("street_number")) {
buildingName = component["long_name"]; // Building Name
} else if (types.contains("postal_code")) {
pincode = component["long_name"]; // Extract Pin Code
}
}
// setState(() {
// // _address = formattedAddress;
// _roadName = roadName;
// _colony = colony;
// _buildingName = buildingName;
// });
_pincodeController.text = pincode;
_RoadController.text = result["formatted_address"];
print(
"Full Address: ${result["formatted_address"]} ${response.body} sdfsgd ${pincode}");
print("Road Name: $roadName");
print("Colony: $colony");
print("Building Name: $buildingName");
} else {}
} else {}
} catch (e) {
print(e);
print("Error fetching address: $e");
}
}
@@ -222,13 +145,26 @@ class _MapScreenState extends State<MapScreen> {
}
}
// {
// "name": "Socket Mall",
// "pincode": "400001",
// "phoneNumber": "+919876543210",
// "alternatePhoneNumber": "+919876543211",
// "addressLine": "123, Main Street, Apartment 4B",
// "landmark": "Near Central Park",
// "addressType": "HOME",
// "isDefault": false,
// "additionalInstructions": "Please ring doorbell twice"
// }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Pick Location")),
appBar: AppBar(title: Text("Add Delivery address")),
body: Column(
children: [
Expanded(
Container(
height: 200.h,
child: GoogleMap(
initialCameraPosition: CameraPosition(
target: _selectedLocation,
@@ -239,54 +175,152 @@ class _MapScreenState extends State<MapScreen> {
},
markers: {
Marker(
markerId: MarkerId("selectedLocation"),
markerId: MarkerId("selected Location"),
position: _selectedLocation,
)
},
onTap: _onMapTapped,
),
),
Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Selected Address:",
style: TextStyle(fontWeight: FontWeight.bold)),
SizedBox(height: 5),
Text(_address, style: TextStyle(fontSize: 16)),
SizedBox(height: 10),
TextField(
controller: _pincodeController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Enter Pincode",
border: OutlineInputBorder(),
SingleChildScrollView(
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10)],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Text("Selected Address:",
// style: TextStyle(fontWeight: FontWeight.bold)),
// SizedBox(height: 5),
// Text(_address, style: TextStyle(fontSize: 16)),
SizedBox(height: 10),
TextField(
controller: _fullNameController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Full Name (Required)*",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
onChanged: (value) {
setState(() {
_pincode = value;
});
},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
SizedBox(height: 10),
ElevatedButton(
onPressed: () {
Navigator.pop(context, {
"location": _selectedLocation,
"address": _address,
"pincode": _pincode
});
},
child: Text("Confirm Location"),
),
],
SizedBox(height: 10),
TextField(
controller: _PhoneNumberController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Phone Number (Required)*",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
SizedBox(height: 10),
Row(
children: [
Expanded(
child: TextField(
controller: _pincodeController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Enter Pincode",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
),
SizedBox(
width: 10,
),
Expanded(
child: TextField(
controller: _addressTypeController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Address Type",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
),
],
),
SizedBox(height: 10),
TextField(
controller: _HouseNoController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "House No, Building Name (Required)*",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
SizedBox(height: 10),
TextField(
controller: _RoadController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: "Road Name, Area , Colony(Required)*",
border: OutlineInputBorder(),
),
onChanged: (value) {},
onSubmitted:
_updateLocationFromPincode, // Auto-update on enter
),
SizedBox(height: 10),
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: [
const SizedBox(
width: 10,
),
Text(
"Save Address",
style: context.customMedium(Colors.white, 20),
),
],
),
),
),
// ElevatedButton(
// onPressed: () {
// Navigator.pop(context, {
// "location": _selectedLocation,
// "address": _address,
// "pincode": _pincode
// });
// },
// child: Text("Confirm Location"),
// ),
],
),
),
),
],
@@ -294,143 +328,3 @@ class _MapScreenState extends State<MapScreen> {
);
}
}
// import 'dart:convert';
// import 'package:flutter/material.dart';
// import 'package:geolocator/geolocator.dart';
// import 'package:http/http.dart' as http;
// const String googleApiKey = "AIzaSyAi3_Dls63iGs7Nccgdm-4FkS0rhT03-4U"; // Replace with your API key
// class LocationScreen extends StatefulWidget {
// @override
// _LocationScreenState createState() => _LocationScreenState();
// }
// class _LocationScreenState extends State<LocationScreen> {
// String _address = "Fetching location...";
// String _roadName = "";
// String _colony = "";
// String _buildingName = "";
// @override
// void initState() {
// super.initState();
// _fetchCurrentLocation();
// }
// // Fetch Current Location
// Future<void> _fetchCurrentLocation() async {
// try {
// Position position = await Geolocator.getCurrentPosition(
// desiredAccuracy: LocationAccuracy.bestForNavigation, // High Accuracy
// );
// _getAddressFromLatLng(position.latitude, position.longitude);
// } catch (e) {
// print("Error fetching location: $e");
// setState(() {
// _address = "Failed to get location.";
// });
// }
// }
// // Get Address from Latitude and Longitude
// Future<void> _getAddressFromLatLng(double lat, double lng) async {
// final String url =
// "https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=$googleApiKey";
// try {
// final response = await http.get(Uri.parse(url));
// if (response.statusCode == 200) {
// final data = json.decode(response.body);
// if (data["status"] == "OK") {
// var result = data["results"][0]; // First result is most accurate
// String formattedAddress = result["formatted_address"];
// List components = result["address_components"];
// String roadName = "";
// String colony = "";
// String buildingName = "";
// for (var component in components) {
// List types = component["types"];
// if (types.contains("route")) {
// roadName = component["long_name"]; // Road Name
// } else if (types.contains("sublocality_level_1") || types.contains("locality")) {
// colony = component["long_name"]; // Colony Name
// } else if (types.contains("premise") || types.contains("street_number")) {
// buildingName = component["long_name"]; // Building Name
// }
// }
// setState(() {
// _address = formattedAddress;
// _roadName = roadName;
// _colony = colony;
// _buildingName = buildingName;
// });
// print("Full Address: $formattedAddress");
// print("Road Name: $roadName");
// print("Colony: $colony");
// print("Building Name: $buildingName");
// } else {
// setState(() {
// _address = "No address found";
// });
// }
// } else {
// setState(() {
// _address = "Failed to fetch address";
// });
// }
// } catch (e) {
// print("Error fetching address: $e");
// setState(() {
// _address = "Error fetching address";
// });
// }
// }
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(title: Text("Location Details")),
// body: Padding(
// padding: const EdgeInsets.all(16.0),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text("Full Address:", style: TextStyle(fontWeight: FontWeight.bold)),
// Text(_address, style: TextStyle(fontSize: 16)),
// SizedBox(height: 10),
// Text("Road Name:", style: TextStyle(fontWeight: FontWeight.bold)),
// Text(_roadName, style: TextStyle(fontSize: 16)),
// SizedBox(height: 10),
// Text("Colony:", style: TextStyle(fontWeight: FontWeight.bold)),
// Text(_colony, style: TextStyle(fontSize: 16)),
// SizedBox(height: 10),
// Text("Building Name:", style: TextStyle(fontWeight: FontWeight.bold)),
// Text(_buildingName, style: TextStyle(fontSize: 16)),
// SizedBox(height: 20),
// ElevatedButton(
// onPressed: _fetchCurrentLocation,
// child: Text("Refresh Location"),
// ),
// ],
// ),
// ),
// );
// }
// }