fixedlocationhomepage
This commit is contained in:
@@ -992,7 +992,7 @@
|
||||
"languageVersion": "3.4"
|
||||
}
|
||||
],
|
||||
"generated": "2025-02-14T13:22:19.642868Z",
|
||||
"generated": "2025-02-22T07:04:58.909640Z",
|
||||
"generator": "pub",
|
||||
"generatorVersion": "3.4.4",
|
||||
"flutterRoot": "file:///Users/rajeevsingh/Documents/allSoftwares/flutter",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -293,7 +293,7 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
};
|
||||
}
|
||||
|
||||
print("ksdjfkgjlhdfkg ${data}");
|
||||
|
||||
try {
|
||||
var result = await _homeRepo.paymentOrder(data);
|
||||
return result.fold(
|
||||
@@ -319,6 +319,15 @@ class AddtocartProvider extends ChangeNotifier {
|
||||
);
|
||||
} catch (e) {
|
||||
ispaymentLoader = false;
|
||||
|
||||
Fluttertoast.showToast(
|
||||
msg: "Internal server error!",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
backgroundColor: Colors.red,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.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';
|
||||
@@ -13,6 +17,10 @@ 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';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ProductProvider extends ChangeNotifier {
|
||||
final _homeRepo = getIt<ProductRepo>();
|
||||
|
||||
@@ -95,21 +103,24 @@ class ProductProvider extends ChangeNotifier {
|
||||
|
||||
List<Product> homeproducts = [];
|
||||
|
||||
|
||||
Future<void> getHomeProduct(BuildContext context,String id, String search) async
|
||||
{
|
||||
Future<void> getHomeProduct(BuildContext context, String id, String search,
|
||||
String minPrice, String maxprice, orderby) async {
|
||||
isHomeLoadingg = true;
|
||||
|
||||
notifyListeners();
|
||||
var data = {"minPrice": "", "minPrice": "", "search": search};
|
||||
var result = await _homeRepo.getAllProduct(data, context,id);
|
||||
var data = {
|
||||
"minPrice": "${minPrice}",
|
||||
"minPrice": "${maxprice}",
|
||||
"search": search,
|
||||
"sortBy": orderby
|
||||
};
|
||||
var result = await _homeRepo.getAllProduct(data, context, id);
|
||||
return result.fold(
|
||||
(error) {
|
||||
isLoadingg = false;
|
||||
notifyListeners();
|
||||
},
|
||||
(response)
|
||||
{
|
||||
(response) {
|
||||
homeproducts = response.data!;
|
||||
|
||||
isHomeLoadingg = false;
|
||||
@@ -147,11 +158,10 @@ class ProductProvider extends ChangeNotifier {
|
||||
|
||||
bool isBestdealingloading = true;
|
||||
|
||||
Future<void> getBestDealProduct(BuildContext context,String search) async
|
||||
{
|
||||
Future<void> getBestDealProduct(BuildContext context, String search) async {
|
||||
isBestdealingloading = true;
|
||||
notifyListeners();
|
||||
var data = {"minPrice": "", "minPrice": "", "search": search};
|
||||
var data = {"minPrice": "", "minPrice": "", "search": search};
|
||||
var result = await _homeRepo.getBestDealProduct(data, context);
|
||||
return result.fold(
|
||||
(error) {
|
||||
@@ -166,9 +176,6 @@ class ProductProvider extends ChangeNotifier {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
List<Datum> categoryList = [];
|
||||
|
||||
bool iscategroyloading = true;
|
||||
@@ -675,4 +682,83 @@ class ProductProvider extends ChangeNotifier {
|
||||
_selectedIndex = index;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> determinePosition() async {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationPermission permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
return;
|
||||
}
|
||||
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
);
|
||||
LatLng currentLatLng = LatLng(position.latitude, position.longitude);
|
||||
|
||||
_getAddressFromLatLng(position.latitude, position.longitude);
|
||||
}
|
||||
|
||||
String googleApiKey = "AIzaSyAi3_Dls63iGs7Nccgdm-4FkS0rhT03-4U";
|
||||
|
||||
String getCurrentAdd = '';
|
||||
|
||||
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
|
||||
|
||||
// _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;
|
||||
// });
|
||||
|
||||
getCurrentAdd = result["formatted_address"] + pincode;
|
||||
notifyListeners();
|
||||
|
||||
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("Error fetching address: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,6 @@ class OrderProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -122,13 +122,13 @@ class ProfileProvider extends ChangeNotifier {
|
||||
await SharedPrefUtils.saveUser(user: response);
|
||||
allitem = response!;
|
||||
|
||||
_profile = response.img;
|
||||
_name = response.firstName + " " + response.lastName;
|
||||
_email = response.email;
|
||||
_profile = response.img ?? '';
|
||||
_name = response.firstName ?? "" + " " + response.lastName ?? '';
|
||||
_email = response.email ?? "";
|
||||
|
||||
APPSTRING.userName = response.firstName;
|
||||
APPSTRING.userLastName = response.lastName;
|
||||
APPSTRING.userProfile = response.img;
|
||||
APPSTRING.userName = response.firstName ?? "";
|
||||
APPSTRING.userLastName = response.lastName ?? "";
|
||||
APPSTRING.userProfile = response.img ?? "";
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
},
|
||||
|
||||
@@ -1,60 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/src/logic/provider/home_provider.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 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,
|
||||
),
|
||||
],
|
||||
);
|
||||
return Consumer<ProductProvider>(builder: (context, provider, child) {
|
||||
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(
|
||||
provider.getCurrentAdd,
|
||||
// "639| Elgin St. Celina, Delaware 10299",
|
||||
style: context.customMedium(APPCOLOR.grey666666, 14),
|
||||
),
|
||||
],
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
// Icon(
|
||||
// MdiIcons.shoppingOutline,
|
||||
// color: APPCOLOR.balck1A1A1A,
|
||||
// size: 30,
|
||||
// ),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,12 +33,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
final productProvider =
|
||||
Provider.of<ProductProvider>(context, listen: false);
|
||||
productProvider .determinePosition();
|
||||
|
||||
productProvider.getBanners(context);
|
||||
productProvider.getHomeProduct(context, "", '');
|
||||
productProvider.getBestDealProduct(context,'');
|
||||
productProvider.getHomeProduct(context, "", '', '', '', '');
|
||||
productProvider.getBestDealProduct(context, '');
|
||||
productProvider.getAllcategory(context);
|
||||
|
||||
|
||||
getUserDetails();
|
||||
});
|
||||
}
|
||||
@@ -69,7 +71,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Row(
|
||||
children: [
|
||||
Consumer<ProductProvider>(
|
||||
builder: (context, provider, child) {
|
||||
builder: (context, provider, child)
|
||||
{
|
||||
return Expanded(
|
||||
child: Container(
|
||||
height: 50,
|
||||
@@ -86,8 +89,8 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
fillColor: Colors.transparent,
|
||||
suffixIcon: InkWell(
|
||||
onTap: () {
|
||||
provider.getHomeProduct(
|
||||
context, "", provider.searchValue);
|
||||
provider.getHomeProduct(context, "",
|
||||
provider.searchValue, '', '', '');
|
||||
},
|
||||
child: Icon(MdiIcons.magnify)),
|
||||
hintText: 'Search',
|
||||
@@ -659,7 +662,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
},
|
||||
)
|
||||
: provider.homeproducts.isEmpty
|
||||
? Center(child: Text('No products available'))
|
||||
? Center(child: Text(''))
|
||||
: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: provider.homeproducts.length,
|
||||
@@ -735,10 +738,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
Divider(
|
||||
thickness: 0.2,
|
||||
),
|
||||
_buildSortOption(context, sortProvider, 0, "Relevance"),
|
||||
_buildSortOption(context, sortProvider, 1, "Popularity"),
|
||||
_buildSortOption(context, sortProvider, 0, "All"),
|
||||
_buildSortOption(context, sortProvider, 1, "Relevance"),
|
||||
_buildSortOption(context, sortProvider, 2, "Popularity"),
|
||||
_buildSortOption(
|
||||
context, sortProvider, 2, "Price: Low to High"),
|
||||
context, sortProvider, 3, "Price: Low to High"),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -758,7 +762,24 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
? Icon(Icons.check_circle, color: Colors.green)
|
||||
: Icon(Icons.radio_button_unchecked, color: Colors.grey),
|
||||
onTap: () {
|
||||
provider.getHomeProduct(context, '', '');
|
||||
switch (index) {
|
||||
case 0:
|
||||
provider.getHomeProduct(context, '', '', "", "", '');
|
||||
break;
|
||||
case 1:
|
||||
provider.getHomeProduct(context, '', '', "", "", "featured");
|
||||
break;
|
||||
case 2:
|
||||
provider.getHomeProduct(context, '', '', "", "", "popularity");
|
||||
break;
|
||||
case 3:
|
||||
provider.getHomeProduct(context, '', '', "100", "100000000", '');
|
||||
break;
|
||||
default:
|
||||
provider.getHomeProduct(context, '', '', "", "", '');
|
||||
}
|
||||
|
||||
// provider.getHomeProduct(context, '', '', "100", "100000000");
|
||||
provider.setSelectedIndex(context, index);
|
||||
Navigator.pop(context); // Close the bottom sheet
|
||||
},
|
||||
|
||||
@@ -86,7 +86,8 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
padding: context.bodyAllPadding.copyWith(bottom: 20),
|
||||
child: Center(
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
onTap: () async
|
||||
{
|
||||
if (_formKey.currentState?.validate() ?? false) {
|
||||
final success =
|
||||
await pageNotifier.sendOtp(phoneController.text, context);
|
||||
|
||||
@@ -93,6 +93,8 @@ class _SingnuScreenState extends State<SingnuScreen> {
|
||||
},
|
||||
),
|
||||
])),
|
||||
|
||||
|
||||
Text(
|
||||
"",
|
||||
style: context.customMedium(APPCOLOR.balck1A1A1A, 18),
|
||||
|
||||
@@ -120,6 +120,9 @@ class _AddLocationAddressState extends State<AddLocationAddress> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void _onMapTapped(LatLng tappedPoint) {
|
||||
setState(() {
|
||||
_selectedLocation = tappedPoint;
|
||||
|
||||
@@ -85,7 +85,8 @@ class _LoginOtpScreenState extends State<LoginOtpScreen> {
|
||||
style: const TextStyle(fontSize: 17),
|
||||
textFieldAlignment: MainAxisAlignment.spaceBetween,
|
||||
fieldStyle: FieldStyle.box,
|
||||
onCompleted: (pin) async {
|
||||
onCompleted: (pin) async
|
||||
{
|
||||
final success = await pageNotifier.loginOtp(pin, context);
|
||||
|
||||
if (success)
|
||||
|
||||
@@ -32,8 +32,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
var top = 0.0;
|
||||
|
||||
@override
|
||||
void initState()
|
||||
{
|
||||
void initState() {
|
||||
Provider.of<ProfileProvider>(context, listen: false).getProfile(context);
|
||||
getUserDetails();
|
||||
super.initState();
|
||||
@@ -53,8 +52,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
body: NestedScrollView(
|
||||
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
|
||||
return <Widget>[
|
||||
Consumer<ProfileProvider>(builder: (context, provider, child)
|
||||
{
|
||||
Consumer<ProfileProvider>(builder: (context, provider, child) {
|
||||
return SliverAppBar(
|
||||
expandedHeight: 180.0,
|
||||
floating: false,
|
||||
@@ -187,18 +185,18 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
title: const Text('Change Password'),
|
||||
trailing: Icon(MdiIcons.chevronRight),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
// Navigator.of(context).push(MaterialPageRoute(
|
||||
// builder: (context) {
|
||||
// return const CardCheckoutScreen();
|
||||
// },
|
||||
// ));
|
||||
},
|
||||
leading: Icon(MdiIcons.cardOutline),
|
||||
title: const Text('Payment Method'),
|
||||
trailing: Icon(MdiIcons.chevronRight),
|
||||
),
|
||||
// ListTile(
|
||||
// onTap: () {
|
||||
// // Navigator.of(context).push(MaterialPageRoute(
|
||||
// // builder: (context) {
|
||||
// // return const CardCheckoutScreen();
|
||||
// // },
|
||||
// // ));
|
||||
// },
|
||||
// leading: Icon(MdiIcons.cardOutline),
|
||||
// title: const Text('Payment Method'),
|
||||
// trailing: Icon(MdiIcons.chevronRight),
|
||||
// ),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
context.push(MyRoutes.MYORDER);
|
||||
@@ -207,18 +205,18 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
title: const Text('My Order'),
|
||||
trailing: Icon(MdiIcons.chevronRight),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return const NotificationScreen();
|
||||
},
|
||||
));
|
||||
},
|
||||
leading: Icon(MdiIcons.bellOutline),
|
||||
title: const Text('Notifications'),
|
||||
trailing: Icon(MdiIcons.chevronRight),
|
||||
),
|
||||
// ListTile(
|
||||
// onTap: () {
|
||||
// Navigator.of(context).push(MaterialPageRoute(
|
||||
// builder: (context) {
|
||||
// return const NotificationScreen();
|
||||
// },
|
||||
// ));
|
||||
// },
|
||||
// leading: Icon(MdiIcons.bellOutline),
|
||||
// title: const Text('Notifications'),
|
||||
// trailing: Icon(MdiIcons.chevronRight),
|
||||
// ),
|
||||
// ListTile(
|
||||
// onTap: () {
|
||||
// Navigator.of(context).push(MaterialPageRoute(
|
||||
@@ -284,7 +282,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
print("fjnghkjfjghj");
|
||||
Provider.of<ProductProvider>(context, listen: false)
|
||||
.customerLogOut(context);
|
||||
},
|
||||
|
||||
@@ -29,11 +29,12 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
Future.delayed(const Duration(seconds: 2), () async {
|
||||
Future.delayed(const Duration(seconds: 2), () async
|
||||
{
|
||||
|
||||
Provider.of<BottomNavProvider>(context, listen: false)
|
||||
.refreshToken(context);
|
||||
if (await SharedPrefUtils.isFreshInstall()) {
|
||||
Provider.of<BottomNavProvider>(context, listen: false) .refreshToken(context);
|
||||
if (await SharedPrefUtils.isFreshInstall())
|
||||
{
|
||||
context.clearAndPush(routePath: MyRoutes.ONBOARDING);
|
||||
} else {
|
||||
context.clearAndPush(routePath: MyRoutes.BOTTOMNAV);
|
||||
|
||||
@@ -46,7 +46,7 @@ class SharedPrefUtils {
|
||||
}) async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
|
||||
print("lkdjglkdfhgkhl ${user.firstName}");
|
||||
print("lkdjglkdfhgkhl ${user.firstName ?? " "}");
|
||||
await prefs.setString(KEY_FIRSTNAME, user.firstName ?? "");
|
||||
await prefs.setString(KEY_LAST_NAME, user.lastName ?? "");
|
||||
await prefs.setString(KEY_EMAIL, user.email ?? " ");
|
||||
|
||||
Reference in New Issue
Block a user