-
Notifications
You must be signed in to change notification settings - Fork 0
#16 - Profile details #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d96b521
00a4720
05e118e
2f76dea
00a2c81
c500b6c
7a4c5fc
39e2d92
97f8c3b
531ebc1
0ef6d1d
0f47170
3349712
3b47868
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/data/providers/profile_repository_provider.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/domain/usecases/get_user_profile_usecase.dart'; | ||
|
|
||
| final getUserProfileUseCaseProvider = Provider<GetUserProfileUseCase>((ref) { | ||
| final repository = ref.watch(profileRepositoryProvider); | ||
| return GetUserProfileUseCase(repository); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import 'package:interns2025b_mobile/src/features/profile/domain/repositories/profile_repository.dart'; | ||
| import 'package:interns2025b_mobile/src/shared/domain/models/user_model.dart'; | ||
|
|
||
| class GetUserProfileUseCase { | ||
| final ProfileRepository repository; | ||
|
|
||
| GetUserProfileUseCase(this.repository); | ||
|
|
||
| Future<User> call(int id) { | ||
| return repository.getUserProfile(id); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/domain/usecases/get_profile_usecase.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/domain/usecases/get_user_profile_usecase.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/presentation/providers/profile_details_user_provider.dart'; | ||
| import 'package:interns2025b_mobile/src/features/profile/presentation/providers/profile_user_provider.dart'; | ||
|
|
||
| class ProfileDetailsController extends ChangeNotifier { | ||
| final Ref ref; | ||
| final GetUserProfileUseCase getUserProfileUseCase; | ||
| final GetProfileUseCase getProfileUseCase; | ||
|
|
||
| ProfileDetailsController( | ||
| this.ref, | ||
| this.getUserProfileUseCase, | ||
| this.getProfileUseCase, | ||
| ); | ||
|
|
||
| bool _isLoading = false; | ||
| bool get isLoading => _isLoading; | ||
|
|
||
| Future<void> loadUserById(int userId, BuildContext context) async { | ||
| _isLoading = true; | ||
| notifyListeners(); | ||
|
|
||
| final currentUser = ref.read(profileUserProvider); | ||
| final isSelf = currentUser != null && currentUser.id == userId; | ||
|
|
||
| final user = isSelf | ||
| ? await getProfileUseCase() | ||
| : await getUserProfileUseCase(userId); | ||
|
|
||
| ref.read(profileDetailsUserProvider.notifier).state = user; | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,51 @@ | ||||||
| import 'package:flutter/material.dart'; | ||||||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||||||
| import 'package:interns2025b_mobile/l10n/generated/app_localizations.dart'; | ||||||
| import 'package:interns2025b_mobile/src/features/profile/presentation/providers/user_profile_by_id_provider.dart'; | ||||||
| import 'package:interns2025b_mobile/src/features/profile/presentation/widgets/profile_info_card.dart'; | ||||||
| import 'package:interns2025b_mobile/src/shared/presentation/theme/app_colors.dart'; | ||||||
| import 'package:interns2025b_mobile/src/shared/presentation/widgets/navigation_bar.dart'; | ||||||
|
|
||||||
| class ProfileDetailsPage extends ConsumerWidget { | ||||||
| const ProfileDetailsPage({super.key}); | ||||||
|
|
||||||
| @override | ||||||
| Widget build(BuildContext context, WidgetRef ref) { | ||||||
| final userId = ModalRoute.of(context)!.settings.arguments as int; | ||||||
| final topPadding = MediaQuery.of(context).padding.top; | ||||||
| final localization = AppLocalizations.of(context)!.failedToLoadUserProfile; | ||||||
|
||||||
| final localization = AppLocalizations.of(context)!.failedToLoadUserProfile; | |
| final errorMessage = AppLocalizations.of(context)!.failedToLoadUserProfile; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loadUserById method sets _isLoading to true but never sets it back to false. This will cause the loading state to persist indefinitely. Add
_isLoading = false; notifyListeners();before the method ends.