fixed issue update profile

This commit is contained in:
2025-02-12 00:37:02 +05:30
parent ad7903d1e3
commit cec162176e
18 changed files with 2011 additions and 196 deletions

View File

@@ -3,6 +3,7 @@ import 'package:grocery_app/src/core/network_services/service_locator.dart';
import 'package:grocery_app/src/data/user_profile.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/constants/string_constant.dart';
class BottomNavProvider with ChangeNotifier {
int _currentIndex = 0;
@@ -16,51 +17,17 @@ class BottomNavProvider with ChangeNotifier {
_pageController.jumpToPage(index);
notifyListeners();
}
UserProfile allitem = UserProfile();
final _homeRepo = getIt<ProductRepo>();
bool isLoading = true;
Future<void> getProfile(BuildContext context) async {
print("kjdkjghdfjglhjdfhgldflghjkldfjgh");
isLoading = true;
notifyListeners();
var data = {};
try {
var result = await _homeRepo.getProfile(data);
return result.fold(
(error) {
isLoading = false;
notifyListeners();
},
(response) async {
print("kjdshgkjhdfkjg ${response.firstName}");
await SharedPrefUtils.saveUser(user: response);
allitem = response!;
isLoading = false;
notifyListeners();
},
);
} catch (e) {
isLoading = false;
notifyListeners();
}
}
Future<bool> refreshToken(BuildContext context) async {
var data = {"refresh_token": "${await SharedPrefUtils.getRefreshToken()}"};
var result = await _homeRepo.refreshToken(data, context);
return result.fold(
(error) {
return true;
},
(response) {
return true;
},
);

View File

@@ -6,8 +6,11 @@ import 'package:grocery_app/src/core/utils/snack_bar.dart';
import 'package:grocery_app/src/data/user_profile.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/utils/constants/shared_pref_utils.dart';
import 'package:grocery_app/utils/extensions/extensions.dart';
import '../../../utils/constants/string_constant.dart';
class ProfileProvider extends ChangeNotifier {
bool _isImageLoading = false;
bool get isImageLoading => _isImageLoading;
@@ -42,7 +45,7 @@ class ProfileProvider extends ChangeNotifier {
showTopSnackBar(context, message, color);
}
Future<bool> createStore(
Future<bool> updateProfile(
BuildContext context, String firstName, String lastName) async {
context.showLoader(show: true);
@@ -68,7 +71,8 @@ class ProfileProvider extends ChangeNotifier {
return false;
},
(response) {
Navigator.pop(context);
getProfile(context);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Profile updated"),
@@ -78,8 +82,7 @@ class ProfileProvider extends ChangeNotifier {
return true;
},
);
} catch (e)
{
} catch (e) {
context.showLoader(show: false);
ScaffoldMessenger.of(context).showSnackBar(
@@ -91,4 +94,48 @@ class ProfileProvider extends ChangeNotifier {
return false;
}
}
final _homeRepo = getIt<ProductRepo>();
UserProfile allitem = UserProfile();
bool isLoading = true;
String _profile = '';
String get profile => _profile;
String _name = '';
String get name => _name;
String _email = '';
String get email => _email;
Future<void> getProfile(BuildContext context) async {
isLoading = true;
notifyListeners();
var data = {};
try {
var result = await _homeRepo.getProfile(data);
return result.fold(
(error) {
isLoading = false;
notifyListeners();
},
(response) async {
await SharedPrefUtils.saveUser(user: response);
allitem = response!;
_profile = response.img;
_name = response.firstName + " " + response.lastName;
_email = response.email;
APPSTRING.userName = response.firstName;
APPSTRING.userLastName = response.lastName;
APPSTRING.userProfile = response.img;
isLoading = false;
notifyListeners();
},
);
} catch (e) {
isLoading = false;
notifyListeners();
}
}
}

View File

@@ -221,10 +221,11 @@ class ProductRepo {
try {
var response = await _productService.updateProfile(data);
print("kdjfgkljfdkjlghflkgjh ${response}");
final String model = response.toString();
return right(model);
} on DioException catch (e) {
} on DioException catch (e)
{
var error = CustomDioExceptions.handleError(e);
return left(error);
}

View File

@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:grocery_app/src/logic/provider/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/logic/provider/profile_provider.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';
@@ -19,8 +20,7 @@ class BottomBarWidget extends StatefulWidget {
_BottomBarState createState() => _BottomBarState();
}
class _BottomBarState extends State<BottomBarWidget>
{
class _BottomBarState extends State<BottomBarWidget> {
int _currentIndex = 0;
PageController bottomWidgetPageController = PageController(
initialPage: 0,
@@ -40,7 +40,7 @@ class _BottomBarState extends State<BottomBarWidget>
@override
void initState() {
Provider.of<BottomNavProvider>(context, listen: false).getProfile(context);
Provider.of<ProfileProvider>(context, listen: false).getProfile(context);
_currentIndex = 0;
bottomWidgetPageController = PageController(
initialPage: 0,

View File

@@ -43,6 +43,8 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
firstController.text = APPSTRING.userName;
lastController.text = APPSTRING.userLastName;
profile = APPSTRING.userProfile;
print("jshdgjkdhfg ${profile}");
}
/// Pick image from gallery or camera
@@ -70,6 +72,7 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
@override
Widget build(BuildContext context) {
print("jkdfhgkjdfg ${_image} ${profile}");
return Scaffold(
appBar: AppBar(
centerTitle: true,
@@ -111,9 +114,17 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
Expanded(
child: InkWell(
onTap: imageProvider.isImageLoading
? () {
imageProvider.createStore(context,
firstController.text, lastController.text);
? () async {
var status = await imageProvider.updateProfile(
context,
firstController.text,
lastController.text);
if (status) {
print('dksfjghdkfgh');
Navigator.pop(context);
}
}
: null,
child: Container(
@@ -153,16 +164,14 @@ class _EditProfileScreenState extends State<EditProfileScreen> {
Stack(
alignment: Alignment.center,
children: [
//
CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
backgroundColor: Colors.grey,
backgroundImage: _image != null
? FileImage(_image!) as ImageProvider
? FileImage(_image!)
: (profile != null && profile!.isNotEmpty
? NetworkImage(profile!)
: const AssetImage("assets/default_profile.png")
as ImageProvider),
: const AssetImage("assets/default_profile.png")),
),
Positioned(
bottom: 0,

View File

@@ -41,7 +41,10 @@ class _HomeScreenState extends State<HomeScreen> {
}
getUserDetails() async {
APPSTRING.userName = (await SharedPrefUtils.getUserName())!;
APPSTRING.userName = (await SharedPrefUtils.getFirstName())!;
print("kdjfkgjhdkfgj ${await SharedPrefUtils.getFirstName()}");
APPSTRING.emailName = (await SharedPrefUtils.getUserEmail())!;
APPSTRING.userProfile = (await SharedPrefUtils.getUserProfile())!;
APPSTRING.userLastName = (await SharedPrefUtils.getLastName())!;
@@ -507,7 +510,7 @@ class _HomeScreenState extends State<HomeScreen> {
),
)
: provider.banner.isEmpty
? Center(child: Text('No products available'))
? SizedBox.shrink()
: CarouselSlider(
options: CarouselOptions(
height: 180,

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:grocery_app/src/common_widget/network_image.dart';
import 'package:grocery_app/src/data/myOrder.dart';
import 'package:intl/intl.dart';
class OrderDetailsScreen extends StatefulWidget {
final Datum order;
@@ -13,6 +14,20 @@ class OrderDetailsScreen extends StatefulWidget {
class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
int currentStep = 1;
String convertUtcToIst(String utcTime) {
// Parse the UTC time string
DateTime utcDateTime = DateTime.parse(utcTime).toUtc();
// Convert to IST (UTC +5:30)
DateTime istDateTime =
utcDateTime.add(const Duration(hours: 5, minutes: 30));
// Format the IST datetime with AM/PM
String formattedDateTime =
DateFormat("dd-MM-yyyy hh:mm a").format(istDateTime);
return formattedDateTime; // Example: 11-02-2025 10:44 AM
}
@override
Widget build(BuildContext context) {
@@ -54,7 +69,7 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
Text(widget.order.deliveryAddress!.addressLine ?? " ",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
SizedBox(height: 5),
Text(widget.order.createdAt.toString()),
Text(convertUtcToIst(widget.order.createdAt.toString())),
SizedBox(height: 5),
Text(
"Status: ${_getStatusText(widget.order.orderStatus)}",

View File

@@ -7,6 +7,7 @@ import 'package:grocery_app/src/logic/provider/order_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/extensions.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -22,6 +23,21 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
super.initState();
}
String convertUtcToIst(String utcTime) {
// Parse the UTC time string
DateTime utcDateTime = DateTime.parse(utcTime).toUtc();
// Convert to IST (UTC +5:30)
DateTime istDateTime =
utcDateTime.add(const Duration(hours: 5, minutes: 30));
// Format the IST datetime with AM/PM
String formattedDateTime =
DateFormat("dd-MM-yyyy hh:mm a").format(istDateTime);
return formattedDateTime; // Example: 11-02-2025 10:44 AM
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -134,7 +150,7 @@ class _MyOrderScreenState extends State<MyOrderScreen> {
],
),
SizedBox(height: 10),
Text(order.createdAt.toString(),
Text(convertUtcToIst(order.updatedAt.toString()),
style: TextStyle(color: Colors.grey)),
SizedBox(height: 5),
Row(

View File

@@ -2,7 +2,9 @@ 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/bottom_navbar_provider.dart';
import 'package:grocery_app/src/logic/provider/home_provider.dart';
import 'package:grocery_app/src/logic/provider/profile_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';
@@ -29,120 +31,134 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> {
var top = 0.0;
@override
void initState()
{
Provider.of<ProfileProvider>(context, listen: false).getProfile(context);
getUserDetails();
super.initState();
}
getUserDetails() async {
APPSTRING.userName = (await SharedPrefUtils.getFirstName())!;
APPSTRING.emailName = (await SharedPrefUtils.getUserEmail())!;
APPSTRING.userProfile = (await SharedPrefUtils.getUserProfile())!;
APPSTRING.userLastName = (await SharedPrefUtils.getLastName())!;
}
@override
Widget build(BuildContext context) {
print("jdfgkjhgjh ${APPSTRING.userProfile}");
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 180.0,
floating: false,
pinned: true,
backgroundColor: Colors.white,
leading: const SizedBox(),
flexibleSpace: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
top = constraints.biggest.height;
Consumer<ProfileProvider>(builder: (context, provider, child)
{
return SliverAppBar(
expandedHeight: 180.0,
floating: false,
pinned: true,
backgroundColor: Colors.white,
leading: const SizedBox(),
flexibleSpace: LayoutBuilder(builder:
(BuildContext context, BoxConstraints constraints) {
top = constraints.biggest.height;
return FlexibleSpaceBar(
centerTitle: true,
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
top > 100
? Text(
"My Profile",
style:
context.customExtraBold(Colors.white, 14),
)
: const SizedBox(),
const SizedBox(
height: 30,
),
//Spacer(),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
width: 15,
),
Stack(
children: [
AppNetworkImage(
height: top < 150 ? 30 : 50,
width: top < 150 ? 30 : 50,
imageUrl: "${APPSTRING.userProfile ?? ""}" ??
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTdQLwDqDwd2JfzifvfBTFT8I7iKFFevcedYg&s",
radius: 90,
backGroundColor: Colors.white,
boxFit: BoxFit.fill,
),
// top > 100
// ? Positioned(
// bottom: 0,
// right: 0,
// child: Container(
// height: 18,
// width: 18,
// decoration: BoxDecoration(
// color: APPCOLOR.lightGreen,
// border: Border.all(
// color: Colors.white),
// borderRadius:
// BorderRadius.circular(5)),
// child: Center(
// child: Icon(
// MdiIcons.pencil,
// size: 10,
// color: Colors.white,
// ),
// ),
// ))
// : const SizedBox(),
],
),
const SizedBox(
width: 15,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
APPSTRING.userName ?? "",
style: context.customExtraBold(
top < 100 ? Colors.black : Colors.white,
14),
),
Text(
APPSTRING.emailName,
style: context.customRegular(
top < 100 ? Colors.black : Colors.white,
10),
return FlexibleSpaceBar(
centerTitle: true,
title: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
top > 100
? Text(
"My Profile",
style:
context.customExtraBold(Colors.white, 14),
)
],
),
const SizedBox(
width: 15,
),
],
),
],
),
background: Container(
height: 200,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
));
}),
),
: const SizedBox(),
const SizedBox(
height: 30,
),
//Spacer(),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(
width: 15,
),
Stack(
children: [
AppNetworkImage(
height: top < 150 ? 30 : 50,
width: top < 150 ? 30 : 50,
imageUrl: provider.profile ?? "",
radius: 90,
backGroundColor: Colors.white,
boxFit: BoxFit.fill,
),
],
),
const SizedBox(
width: 15,
),
if (provider.name.isNotEmpty) ...{
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
provider.name ?? " ",
style: context.customExtraBold(
top < 100
? Colors.black
: Colors.white,
14),
),
Text(
provider.email,
style: context.customRegular(
top < 100
? Colors.black
: Colors.white,
10),
)
],
),
} else ...{
InkWell(
onTap: () {
context.push(MyRoutes.SIGNUP);
},
child: Text(
"Login ",
style: context.customExtraBold(
top < 100 ? Colors.blue : Colors.blue,
14),
),
)
},
const SizedBox(
width: 15,
),
],
),
],
),
background: Container(
height: 200,
decoration: BoxDecoration(
color: APPCOLOR.lightGreen,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
));
}),
);
})
];
},
body: Column(
@@ -158,7 +174,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) {
return const EditProfileScreen();
return EditProfileScreen();
},
));
},

View File

@@ -36,27 +36,31 @@ class SharedPrefUtils {
static const String STORE_ID = "STORE_ID";
static const String REFRESH_TOKEN = "REFRESH_TOKEN";
static const String KEY_NAME = "user_name";
static const String KEY_LAST_NAME = "user_name";
static const String KEY_EMAIL = "user_email";
static const String KEY_PROFILE = "user_profile";
static const String KEY_FIRSTNAME = "KEY_FIRSTNAME";
static const String KEY_LAST_NAME = "KEY_LAST_NAME";
static const String KEY_EMAIL = "KEY_EMAIL";
static const String KEY_PROFILE = "KEY_PROFILE";
static Future<void> saveUser({
required UserProfile user,
}) async {
print("jdhsfhjdjfhg ${user.img}");
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString(KEY_NAME, user.firstName ?? "");
await prefs.setString(KEY_LAST_NAME, user.lastName ?? "");
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 ?? " ");
await prefs.setString(KEY_PROFILE, user.img ?? " ");
}
static Future<String?> getUserName() async {
static Future<String?> getFirstName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(KEY_NAME);
print("kjdshfgjkhdf ${prefs.getString(KEY_FIRSTNAME)}");
return prefs.getString(KEY_FIRSTNAME);
}
static Future<String?> getLastName() async {
static Future<String?> getLastName() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(KEY_LAST_NAME);
}
@@ -260,17 +264,6 @@ class SharedPrefUtils {
///
///
static Future<String> getFirstName() async {
final sp = await SharedPreferences.getInstance();
final firstName = sp.getString(FIRST_NAME);
print("lkjhdsgkhfdkjg ${sp.getString(FIRST_NAME)}");
return firstName!;
}
static Future<String> getEmail() async {
final sp = await SharedPreferences.getInstance();
return sp.getString(EMAIL) ?? "";