@@ -23,15 +23,16 @@ class ProfileScreen extends ConsumerWidget {
2323
2424 if (username == null || username.isEmpty) {
2525 return const Scaffold (
26+ key: ValueKey ('profile_no_username' ),
2627 body: Center (child: Text ("No username provided" )),
2728 );
2829 }
2930
3031 final asyncUser = ref.watch (profileViewModelProvider (username));
3132
3233 return asyncUser.when (
33- loading: () => const Scaffold (body: Center (child: CircularProgressIndicator ())),
34- error: (err, _) => Scaffold (body: Center (child: Text ("Error: $err " ))),
34+ loading: () => const Scaffold (key : ValueKey ( 'profile_loading' ), body: Center (child: CircularProgressIndicator ())),
35+ error: (err, _) => Scaffold (key : const ValueKey ( 'profile_error' ), body: Center (child: Text ("Error: $err " ))),
3536 data: (user) => _ProfileLoaded (user: user, username: username),
3637 );
3738 }
@@ -68,22 +69,28 @@ class _ProfileLoaded extends ConsumerWidget {
6869 const double avatarRadius = 46 ;
6970
7071 return Scaffold (
72+ key: const ValueKey ('profile_loaded_scaffold' ),
7173 body: RefreshIndicator (
74+ key: const ValueKey ('profile_refresh_indicator' ),
7275 onRefresh: refresh,
7376 child: NestedScrollView (
77+ key: const ValueKey ('profile_nested_scroll' ),
7478 headerSliverBuilder: (_, __) => [
7579 SliverAppBar (
80+ key: const ValueKey ('profile_sliver_appbar' ),
7681 pinned: true ,
7782 expandedHeight: 120 ,
7883 backgroundColor: Colors .white,
7984 leading: IconButton (
85+ key: const ValueKey ('profile_back_button' ),
8086 icon: const Icon (Icons .arrow_back),
8187 onPressed: () => Navigator .pop (context),
8288 ),
8389
8490 actions: [
8591 if (! isOwnProfile)
8692 ProfileMoreMenu (
93+ key: const ValueKey ('profile_more_menu' ),
8794 user: user,
8895 username: username,
8996 onAction: () => refresh (),
@@ -97,16 +104,18 @@ class _ProfileLoaded extends ConsumerWidget {
97104 children: [
98105 Positioned .fill (
99106 child: (user.bannerImageUrl != null && user.bannerImageUrl! .isNotEmpty)
100- ? Image .network (user.bannerImageUrl! , fit: BoxFit .cover)
107+ ? Image .network (key : const ValueKey ( 'profile_banner' ), user.bannerImageUrl! , fit: BoxFit .cover)
101108 : Container (color: Colors .grey.shade300),
102109 ),
103110 Positioned (
104111 bottom: - avatarRadius,
105112 left: 16 ,
106113 child: CircleAvatar (
114+ key: const ValueKey ('profile_avatar_outer' ),
107115 radius: avatarRadius,
108116 backgroundColor: Colors .white,
109117 child: CircleAvatar (
118+ key: const ValueKey ('profile_avatar_inner' ),
110119 radius: avatarRadius - 3 ,
111120 backgroundImage: (user.profileImageUrl != null &&
112121 user.profileImageUrl! .isNotEmpty)
@@ -127,7 +136,9 @@ class _ProfileLoaded extends ConsumerWidget {
127136
128137 // Profile Header (name, handle, bio...)
129138 SliverToBoxAdapter (
139+ key: const ValueKey ('profile_header_section' ),
130140 child: ProfileHeaderWidget (
141+ key: const ValueKey ('profile_header_widget' ),
131142 user: user,
132143 isOwnProfile: isOwnProfile,
133144 onEdited: () => refresh (),
@@ -140,19 +151,21 @@ class _ProfileLoaded extends ConsumerWidget {
140151 child: Column (
141152 children: [
142153 const TabBar (
154+ key: ValueKey ('profile_tabbar' ),
143155 isScrollable: false ,
144156 tabs: [
145- Tab (text: "Posts" ),
146- Tab (text: "Replies" ),
147- Tab (text: "Likes" ),
157+ Tab (key : ValueKey ( 'profile_tab_posts' ), text: "Posts" ),
158+ Tab (key : ValueKey ( 'profile_tab_replies' ), text: "Replies" ),
159+ Tab (key : ValueKey ( 'profile_tab_likes' ), text: "Likes" ),
148160 ],
149161 ),
150162 Expanded (
151163 child: TabBarView (
164+ key: const ValueKey ('profile_tabbar_view' ),
152165 children: [
153- _ProfilePostsTab (userId: user.profileId! .toString ()),
154- _ProfileRepliesTab (userId: user.profileId! .toString ()),
155- _ProfileLikesTab (userId: user.profileId! .toString ()),
166+ _ProfilePostsTab (key : const ValueKey ( 'profile_posts_tab' ), userId: user.profileId! .toString (), ),
167+ _ProfileRepliesTab (key : const ValueKey ( 'profile_replies_tab' ), userId: user.profileId! .toString (), ),
168+ _ProfileLikesTab (key : const ValueKey ( 'profile_likes_tab' ), userId: user.profileId! .toString ()),
156169 ],
157170 ),
158171 ),
@@ -168,7 +181,7 @@ class _ProfileLoaded extends ConsumerWidget {
168181// ----------------------- POSTS TAB -----------------------
169182class _ProfilePostsTab extends ConsumerWidget {
170183 final String userId;
171- const _ProfilePostsTab ({required this .userId});
184+ const _ProfilePostsTab ({super .key, required this .userId});
172185
173186 @override
174187 Widget build (BuildContext context, WidgetRef ref) {
@@ -177,20 +190,22 @@ class _ProfilePostsTab extends ConsumerWidget {
177190 return asyncPosts.when (
178191 data: (tweets) {
179192 if (tweets.isEmpty) {
180- return const Center (child: Text ("No posts yet" ));
193+ return const Center (key : ValueKey ( 'profile_posts_empty' ), child: Text ("No posts yet" ));
181194 }
182195 return ListView .builder (
196+ key: const ValueKey ('profile_posts_list' ),
183197 physics: const AlwaysScrollableScrollPhysics (),
184198 primary: false ,
185199 shrinkWrap: true ,
186200 itemCount: tweets.length,
187201 itemBuilder: (_, i) => TweetSummaryWidget (
202+ key: ValueKey ('profile_post_${tweets [i ].id }' ),
188203 tweetId: tweets[i].id,
189204 tweetData: tweets[i],
190205 ),
191206 );
192207 },
193- loading: () => const Center (child: CircularProgressIndicator ()),
208+ loading: () => const Center (key : ValueKey ( 'profile_posts_loading' ), child: CircularProgressIndicator ()),
194209 error: (_, __) => const Center (child: Text ("Error loading posts" )),
195210 );
196211 }
@@ -199,7 +214,7 @@ class _ProfilePostsTab extends ConsumerWidget {
199214// ----------------------- REPLIES TAB -----------------------
200215class _ProfileRepliesTab extends ConsumerWidget {
201216 final String userId;
202- const _ProfileRepliesTab ({required this .userId});
217+ const _ProfileRepliesTab ({super .key, required this .userId});
203218
204219 @override
205220 Widget build (BuildContext context, WidgetRef ref) {
@@ -211,26 +226,28 @@ class _ProfileRepliesTab extends ConsumerWidget {
211226 return const Center (child: Text ("No replies yet" ));
212227 }
213228 return ListView .builder (
229+ key: ValueKey ('profile_replies_list' ),
214230 physics: const AlwaysScrollableScrollPhysics (),
215231 primary: false ,
216232 shrinkWrap: true ,
217233 itemCount: tweets.length,
218234 itemBuilder: (_, i) => TweetSummaryWidget (
235+ key: ValueKey ('profile_reply_${tweets [i ].id }' ),
219236 tweetId: tweets[i].id,
220237 tweetData: tweets[i],
221238 ),
222239 );
223240 },
224- loading: () => const Center (child: CircularProgressIndicator ()),
225- error: (_, __) => const Center (child: Text ("Error loading replies" )),
241+ loading: () => const Center (key : ValueKey ( 'profile_replies_loading' ), child: CircularProgressIndicator ()),
242+ error: (_, __) => const Center (key : ValueKey ( 'profile_replies_empty' ), child: Text ("Error loading replies" )),
226243 );
227244 }
228245}
229246
230247// ----------------------- LIKES TAB -----------------------
231248class _ProfileLikesTab extends ConsumerWidget {
232249 final String userId;
233- const _ProfileLikesTab ({required this .userId});
250+ const _ProfileLikesTab ({super .key, required this .userId});
234251
235252 @override
236253 Widget build (BuildContext context, WidgetRef ref) {
@@ -242,18 +259,20 @@ class _ProfileLikesTab extends ConsumerWidget {
242259 return const Center (child: Text ("No liked posts" ));
243260 }
244261 return ListView .builder (
262+ key: ValueKey ('profile_likes_list' ),
245263 physics: const AlwaysScrollableScrollPhysics (),
246264 primary: false ,
247265 shrinkWrap: true ,
248266 itemCount: tweets.length,
249267 itemBuilder: (_, i) => TweetSummaryWidget (
268+ key: ValueKey ('profile_like_${tweets [i ].id }' ),
250269 tweetId: tweets[i].id,
251270 tweetData: tweets[i],
252271 ),
253272 );
254273 },
255- loading: () => const Center (child: CircularProgressIndicator ()),
256- error: (_, __) => const Center (child: Text ("Error loading liked posts" )),
274+ loading: () => const Center (key : ValueKey ( 'profile_likes_loading' ), child: CircularProgressIndicator ()),
275+ error: (_, __) => const Center (key : ValueKey ( 'profile_likes_empty' ), child: Text ("Error loading liked posts" )),
257276 );
258277 }
259278}
0 commit comments