Skip to content

Commit 7b6e126

Browse files
brownpub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e
andauthored
fix(mobile): fix agent avatars on mobile (#1837)
Signed-off-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e <e18f3511303812c437d487ac4bf46ad897dc46946699b18ab2e60bf8ee0ea851@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e <e18f3511303812c437d487ac4bf46ad897dc46946699b18ab2e60bf8ee0ea851@sprout-oss.stage.blox.sqprod.co>
1 parent 3e76481 commit 7b6e126

24 files changed

Lines changed: 399 additions & 217 deletions

‎mobile/lib/features/channels/channel_detail_page.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';
77

88
import '../../shared/relay/relay.dart';
99
import '../../shared/theme/theme.dart';
10+
import '../../shared/widgets/avatar_image.dart';
1011
import '../../shared/widgets/frosted_app_bar.dart';
1112
import '../../shared/widgets/frosted_scaffold.dart';
1213
import '../profile/presence_cache_provider.dart';

‎mobile/lib/features/channels/channel_detail_page/app_bar.dart‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,17 @@ class _DmAppBarTitle extends ConsumerWidget {
168168
child: Stack(
169169
clipBehavior: Clip.none,
170170
children: [
171-
CircleAvatar(
171+
AvatarImage(
172+
imageUrl: avatarUrl,
172173
radius: 14,
173174
backgroundColor: context.colors.primaryContainer,
174-
backgroundImage: avatarUrl != null
175-
? NetworkImage(avatarUrl)
176-
: null,
177-
child: avatarUrl == null
178-
? Text(
179-
initial,
180-
style: context.textTheme.labelSmall?.copyWith(
181-
color: context.colors.onPrimaryContainer,
182-
fontWeight: FontWeight.w600,
183-
),
184-
)
185-
: null,
175+
fallback: Text(
176+
initial,
177+
style: context.textTheme.labelSmall?.copyWith(
178+
color: context.colors.onPrimaryContainer,
179+
fontWeight: FontWeight.w600,
180+
),
181+
),
186182
),
187183
Positioned(
188184
right: -1,

‎mobile/lib/features/channels/channel_detail_page/message_bubble.dart‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,17 @@ class _UserAvatar extends StatelessWidget {
150150
profile?.initial ?? (pubkey.isNotEmpty ? pubkey[0].toUpperCase() : '?');
151151
final avatarUrl = profile?.avatarUrl;
152152

153-
return CircleAvatar(
153+
return AvatarImage(
154+
imageUrl: avatarUrl,
154155
radius: 14,
155156
backgroundColor: context.colors.primaryContainer,
156-
backgroundImage: avatarUrl != null ? NetworkImage(avatarUrl) : null,
157-
child: avatarUrl == null
158-
? Text(
159-
initial,
160-
style: context.textTheme.labelSmall?.copyWith(
161-
color: context.colors.onPrimaryContainer,
162-
fontWeight: FontWeight.w600,
163-
),
164-
)
165-
: null,
157+
fallback: Text(
158+
initial,
159+
style: context.textTheme.labelSmall?.copyWith(
160+
color: context.colors.onPrimaryContainer,
161+
fontWeight: FontWeight.w600,
162+
),
163+
),
166164
);
167165
}
168166
}

‎mobile/lib/features/channels/channels_page.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:lucide_icons_flutter/lucide_icons.dart';
99
import '../../shared/auth/auth.dart';
1010
import '../../shared/relay/relay.dart';
1111
import '../../shared/theme/theme.dart';
12+
import '../../shared/widgets/avatar_image.dart';
1213
import '../../shared/widgets/frosted_app_bar.dart';
1314
import '../../shared/widgets/frosted_scaffold.dart';
1415
import '../profile/profile_avatar.dart';

‎mobile/lib/features/channels/channels_page/channel_tile.dart‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,20 +390,18 @@ class _DmAvatar extends ConsumerWidget {
390390
child: Stack(
391391
clipBehavior: Clip.none,
392392
children: [
393-
CircleAvatar(
393+
AvatarImage(
394+
imageUrl: avatarUrl,
394395
radius: 10,
395396
backgroundColor: context.colors.primaryContainer,
396-
backgroundImage: avatarUrl != null ? NetworkImage(avatarUrl) : null,
397-
child: avatarUrl == null
398-
? Text(
399-
initial,
400-
style: context.textTheme.labelSmall?.copyWith(
401-
fontSize: 9,
402-
color: context.colors.onPrimaryContainer,
403-
fontWeight: FontWeight.w600,
404-
),
405-
)
406-
: null,
397+
fallback: Text(
398+
initial,
399+
style: context.textTheme.labelSmall?.copyWith(
400+
fontSize: 9,
401+
color: context.colors.onPrimaryContainer,
402+
fontWeight: FontWeight.w600,
403+
),
404+
),
407405
),
408406
Positioned(
409407
right: -1,

‎mobile/lib/features/channels/channels_page/sheets.dart‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,12 @@ class _NewDirectMessageSheet extends HookConsumerWidget {
297297
children: [
298298
for (final user in availableResults)
299299
ListTile(
300-
leading: CircleAvatar(
301-
backgroundImage: user.avatarUrl != null
302-
? NetworkImage(user.avatarUrl!)
303-
: null,
304-
child: user.avatarUrl == null
305-
? Text(user.label.substring(0, 1).toUpperCase())
306-
: null,
300+
leading: AvatarImage(
301+
imageUrl: user.avatarUrl,
302+
radius: 20,
303+
fallback: Text(
304+
user.label.substring(0, 1).toUpperCase(),
305+
),
307306
),
308307
title: Text(user.label),
309308
subtitle: Text(user.secondaryLabel),

‎mobile/lib/features/channels/compose_bar.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:nostr/nostr.dart' as nostr;
99

1010
import '../../shared/relay/relay.dart';
1111
import '../../shared/theme/theme.dart';
12+
import '../../shared/widgets/avatar_image.dart';
1213
import '../profile/user_cache_provider.dart';
1314
import '../profile/user_profile.dart';
1415
import '../custom_emoji/custom_emoji.dart';

‎mobile/lib/features/channels/compose_bar/suggestions.dart‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,16 @@ class _MentionSuggestions extends StatelessWidget {
4747
return ListTile(
4848
dense: true,
4949
visualDensity: VisualDensity.compact,
50-
leading: CircleAvatar(
50+
leading: AvatarImage(
51+
imageUrl: avatarUrl,
5152
radius: 14,
5253
backgroundColor: context.colors.primaryContainer,
53-
backgroundImage: avatarUrl != null
54-
? NetworkImage(avatarUrl)
55-
: null,
56-
child: avatarUrl == null
57-
? Text(
58-
name[0].toUpperCase(),
59-
style: context.textTheme.labelSmall?.copyWith(
60-
color: context.colors.onPrimaryContainer,
61-
),
62-
)
63-
: null,
54+
fallback: Text(
55+
name[0].toUpperCase(),
56+
style: context.textTheme.labelSmall?.copyWith(
57+
color: context.colors.onPrimaryContainer,
58+
),
59+
),
6460
),
6561
title: Text(name, style: context.textTheme.bodyMedium),
6662
subtitle: _MentionSuggestionInfo.build(

‎mobile/lib/features/channels/members_sheet.dart‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
44
import 'package:lucide_icons_flutter/lucide_icons.dart';
55

66
import '../../shared/theme/theme.dart';
7+
import '../../shared/widgets/avatar_image.dart';
78
import '../profile/user_cache_provider.dart';
89
import '../profile/user_profile.dart';
910
import '../profile/user_status.dart';
@@ -449,29 +450,18 @@ class _RoleSelector extends StatelessWidget {
449450
}
450451
}
451452

452-
class _MemberAvatar extends HookWidget {
453+
class _MemberAvatar extends StatelessWidget {
453454
final String? avatarUrl;
454455
final String initial;
455456

456457
const _MemberAvatar({required this.avatarUrl, required this.initial});
457458

458459
@override
459460
Widget build(BuildContext context) {
460-
final failed = useState(false);
461-
462-
useEffect(() {
463-
failed.value = false;
464-
return null;
465-
}, [avatarUrl]);
466-
467-
final url = avatarUrl;
468-
if (url == null || failed.value) {
469-
return CircleAvatar(child: Text(initial));
470-
}
471-
return CircleAvatar(
472-
backgroundImage: NetworkImage(url),
473-
onBackgroundImageError: (_, _) => failed.value = true,
474-
child: null,
461+
return AvatarImage(
462+
imageUrl: avatarUrl,
463+
radius: 20,
464+
fallback: Text(initial),
475465
);
476466
}
477467
}

‎mobile/lib/features/channels/reaction_row.dart‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
33
import 'package:hooks_riverpod/hooks_riverpod.dart';
44

55
import '../../shared/theme/theme.dart';
6+
import '../../shared/widgets/avatar_image.dart';
67
import '../custom_emoji/custom_emoji_render.dart';
78
import '../profile/user_cache_provider.dart';
89
import '../profile/user_profile.dart';
@@ -279,29 +280,18 @@ class _ReactorTile extends StatelessWidget {
279280
}
280281
}
281282

282-
class _ReactorAvatar extends HookWidget {
283+
class _ReactorAvatar extends StatelessWidget {
283284
final String? avatarUrl;
284285
final String initial;
285286

286287
const _ReactorAvatar({required this.avatarUrl, required this.initial});
287288

288289
@override
289290
Widget build(BuildContext context) {
290-
final failed = useState(false);
291-
292-
useEffect(() {
293-
failed.value = false;
294-
return null;
295-
}, [avatarUrl]);
296-
297-
final url = avatarUrl;
298-
if (url == null || failed.value) {
299-
return CircleAvatar(child: Text(initial));
300-
}
301-
return CircleAvatar(
302-
backgroundImage: NetworkImage(url),
303-
onBackgroundImageError: (_, _) => failed.value = true,
304-
child: null,
291+
return AvatarImage(
292+
imageUrl: avatarUrl,
293+
radius: 20,
294+
fallback: Text(initial),
305295
);
306296
}
307297
}

0 commit comments

Comments
 (0)