fixed issue update profile
This commit is contained in:
@@ -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;
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user