-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create user profile page with delete account function
- Loading branch information
1 parent
a1ea9a1
commit 758c339
Showing
34 changed files
with
231 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
import '../entities/user.dart'; | ||
import '../repositories_abstract/token_provider.dart'; | ||
import '../repositories_abstract/user_repository.dart'; | ||
|
||
class UserUseCase { | ||
final UserRepository repository; | ||
final TokenProvider tokenProvider; | ||
|
||
UserUseCase({required this.repository}); | ||
UserUseCase({required this.repository, required this.tokenProvider}); | ||
|
||
Future<User> fetchMe() async { | ||
return await repository.fetchMe(); | ||
} | ||
|
||
Future<void> deleteAccount() async { | ||
await repository.deleteAccount(); | ||
tokenProvider.deleteToken(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...tion/more/login/forget_password_page.dart → .../settings/login/forget_password_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
52 changes: 52 additions & 0 deletions
52
lib/presentation/settings/viewModels/user_profile_view_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:domain/entities/user.dart'; | ||
import 'package:domain/usecases/user_usercase.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:domain/usecases/auth_usecase.dart'; // Assuming your use cases are here | ||
|
||
class UserProfileViewModel extends ChangeNotifier { | ||
final AuthUseCase authUseCase; | ||
final UserUseCase userUseCase; | ||
|
||
bool isLoading = false; | ||
User? user; | ||
|
||
UserProfileViewModel({required this.authUseCase, required this.userUseCase}) { | ||
fetchUserDetails(); | ||
} | ||
|
||
Future<void> fetchUserDetails() async { | ||
setLoading(true); | ||
try { | ||
user = await userUseCase.fetchMe(); // Assuming a getUser method | ||
} catch (e) { | ||
print("Failed to fetch user details: $e"); | ||
} | ||
setLoading(false); | ||
} | ||
|
||
Future<void> logoutUser() async { | ||
setLoading(true); | ||
try { | ||
await authUseCase.logout(); | ||
} catch (e) { | ||
print("Logout failed: $e"); | ||
} | ||
setLoading(false); | ||
} | ||
|
||
Future<void> deleteUser() async { | ||
setLoading(true); | ||
try { | ||
await userUseCase.deleteAccount(); | ||
print("Account deleted successfully"); | ||
} catch (e) { | ||
print("Account deletion failed: $e"); | ||
} | ||
setLoading(false); | ||
} | ||
|
||
void setLoading(bool value) { | ||
isLoading = value; | ||
notifyListeners(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ntation/more/views/feature_flag_page.dart → ...ion/settings/views/feature_flag_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.