@@ -4,6 +4,7 @@ import 'package:comment_box/comment/comment.dart';
44import 'package:flutter/material.dart' ;
55import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
66import 'package:hooks_riverpod/hooks_riverpod.dart' ;
7+ import '../../user/view_model/profile_picture_view_model.dart' ;
78
89import '../../../../core/utils/storage_utils.dart' ;
910import '../../../../domain/entities/activity.dart' ;
@@ -19,18 +20,19 @@ class ActivityComments extends HookConsumerWidget {
1920 final GlobalKey <FormState > formKey;
2021
2122 final currentUserPictureDataProvider =
22- FutureProvider .family <Uint8List ?, Activity >((ref, activity) async {
23+ FutureProvider .family <String ?, Activity >((ref, activity) async {
2324 final user = await StorageUtils .getUser ();
2425 final provider =
2526 ref.read (activityItemViewModelProvider (activity.id).notifier);
2627
27- return user != null ? provider.getProfilePicture (user.id) : null ;
28+ user != null ? provider.getProfilePicture (user.id) : null ;
29+ return user? .id;
2830 });
2931
3032 final commentUserPictureDataProvider =
31- FutureProvider .family <Uint8List ? , User >((ref, user) async {
33+ FutureProvider .family <void , User >((ref, user) async {
3234 final provider = ref.read (activityItemViewModelProvider (user.id).notifier);
33- return provider.getProfilePicture (user.id);
35+ provider.getProfilePicture (user.id);
3436 });
3537
3638 ActivityComments ({
@@ -39,7 +41,10 @@ class ActivityComments extends HookConsumerWidget {
3941 required this .formKey,
4042 });
4143
42- Widget buildCommentList (WidgetRef ref, List <ActivityComment > comments) {
44+ Widget buildCommentList (
45+ WidgetRef ref,
46+ List <ActivityComment > comments,
47+ ) {
4348 return Expanded (
4449 child: ListView .builder (
4550 itemCount: comments.length,
@@ -49,10 +54,13 @@ class ActivityComments extends HookConsumerWidget {
4954 }
5055
5156 Widget buildCommentItem (WidgetRef ref, ActivityComment comment) {
57+ final profilePicture = ref
58+ .watch (profilePictureViewModelProvider (comment.user.id))
59+ .profilePicture;
5260 return Padding (
5361 padding: const EdgeInsets .fromLTRB (2.0 , 8.0 , 2.0 , 0.0 ),
5462 child: ListTile (
55- leading: buildUserAvatar (ref, comment.user),
63+ leading: buildUserAvatar (ref, comment.user, profilePicture ),
5664 title: GestureDetector (
5765 child: Text (
5866 UserUtils .getNameOrUsername (comment.user),
@@ -82,12 +90,11 @@ class ActivityComments extends HookConsumerWidget {
8290 }
8391
8492 Widget buildCommentChild (
85- WidgetRef ref,
86- AppLocalizations appLocalizations,
87- ActivityItemCommentsViewModel provider,
88- List <ActivityComment > comments,
89- bool displayPreviousComments,
90- ) {
93+ WidgetRef ref,
94+ AppLocalizations appLocalizations,
95+ ActivityItemCommentsViewModel provider,
96+ List <ActivityComment > comments,
97+ bool displayPreviousComments) {
9198 final lastComment = comments.isNotEmpty ? comments.last : null ;
9299
93100 return Column (
@@ -101,7 +108,7 @@ class ActivityComments extends HookConsumerWidget {
101108 );
102109 }
103110
104- Widget buildUserAvatar (WidgetRef ref, User user) {
111+ Widget buildUserAvatar (WidgetRef ref, User user, Uint8List ? profilePicture ) {
105112 return GestureDetector (
106113 child: Container (
107114 height: 50.0 ,
@@ -111,8 +118,9 @@ class ActivityComments extends HookConsumerWidget {
111118 borderRadius: const BorderRadius .all (Radius .circular (50 )),
112119 ),
113120 child: ref.watch (commentUserPictureDataProvider (user)).when (
114- data: (pic) => pic != null
115- ? CircleAvatar (radius: 50 , backgroundImage: MemoryImage (pic))
121+ data: (_) => profilePicture != null
122+ ? CircleAvatar (
123+ radius: 50 , backgroundImage: MemoryImage (profilePicture))
116124 : UserUtils .personIcon,
117125 loading: () => UserUtils .personIcon,
118126 error: (_, __) => UserUtils .personIcon,
@@ -135,7 +143,17 @@ class ActivityComments extends HookConsumerWidget {
135143 height: state.comments.isNotEmpty ? 210 : 80 ,
136144 child: CommentBox (
137145 userImage: currentUserPictureProvider.when (
138- data: (pic) => pic != null ? MemoryImage (pic) : null ,
146+ data: (userId) {
147+ if (userId != null ) {
148+ final profilePicture = ref
149+ .watch (profilePictureViewModelProvider (userId))
150+ .profilePicture;
151+ return profilePicture != null
152+ ? MemoryImage (profilePicture)
153+ : null ;
154+ }
155+ return null ;
156+ },
139157 loading: () => null ,
140158 error: (_, __) => null ,
141159 ),
@@ -145,13 +163,8 @@ class ActivityComments extends HookConsumerWidget {
145163 backgroundColor: ColorUtils .white,
146164 textColor: ColorUtils .mainMedium,
147165 sendWidget: Icon (Icons .send_sharp, size: 30 , color: ColorUtils .main),
148- child: buildCommentChild (
149- ref,
150- appLocalizations,
151- commentsProvider,
152- state.comments,
153- state.displayPreviousComments,
154- ),
166+ child: buildCommentChild (ref, appLocalizations, commentsProvider,
167+ state.comments, state.displayPreviousComments),
155168 ),
156169 );
157170 }
0 commit comments