mirror of
https://github.com/block/buzz.git
synced 2026-11-12 04:12:21 +00:00
Follow-up to #8879, addressing its review. ## Changes - **Community icons load the original again.** `AvatarImageContent` gained a `preferThumbnail` flag, off by default. People and agent avatars turn it on (as #8879 did for every caller); `CommunityAvatar` leaves it off. Community logos are often transparent PNGs, and the relay's JPEG thumbnail renders transparency black. This matches desktop, which shows community icons from the original. - **A missing thumbnail is recorded where its 404 arrives.** Before, only the mounted `Image`'s error builder recorded it. If the avatar scrolled away before a slow 404 came back, the thumbnail URL kept a 30s failure cooldown instead, and showing that avatar again at any size during the cooldown rendered initials and never requested the original. The fetch now records a 404 on a relay `/media/<sha256>.thumb.jpg` URL in the missing-thumbnail set and puts no cooldown on it. ## Tests Two journey tests in `avatar_image_test.dart`, both failing on main and passing here: - An avatar unmounts before its slow thumbnail 404 arrives, then mounts again at another size: it requests the original once, renders it (valid image bytes, no initials), and leaves no cooldown. - A 36pt `CommunityAvatar` with a relay-hosted icon requests and shows only the original. `flutter analyze` is clean. In the full local `flutter test` run, only 12 push and notification tests fail, and they fail the same way on main in this environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
200 lines
7.1 KiB
Dart
200 lines
7.1 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../shared/animated_avatar.dart';
|
|
import '../../shared/theme/theme.dart';
|
|
import '../../shared/widgets/avatar_shape.dart';
|
|
import '../../shared/widgets/avatar_image.dart';
|
|
import '../../shared/widgets/progressive_animated_avatar.dart';
|
|
|
|
/// A directory card using the desktop's portrait and faded-artwork treatment.
|
|
class AgentCard extends StatelessWidget {
|
|
const AgentCard({
|
|
required this.name,
|
|
required this.onOpen,
|
|
this.imageUrl,
|
|
this.location,
|
|
this.footer,
|
|
this.subtitle,
|
|
this.isBestie = false,
|
|
super.key,
|
|
});
|
|
|
|
final String name;
|
|
|
|
/// Whether this is the current community's selected Bestie.
|
|
final bool isBestie;
|
|
final String? subtitle;
|
|
final String? imageUrl;
|
|
|
|
/// Only supplied when the host is known; directory membership is not proof.
|
|
final String? location;
|
|
final VoidCallback onOpen;
|
|
|
|
/// Optional host-owned controls. The card does not invent edit capability.
|
|
final Widget? footer;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final animation = parseAnimatedAvatarUrl(imageUrl);
|
|
final poster = animation?.posterUrl ?? imageUrl;
|
|
final fallback = Center(
|
|
child: Text(
|
|
name.characters.first,
|
|
style: context.textTheme.headlineMedium,
|
|
),
|
|
);
|
|
final portraitFit = usesInsetAgentArtwork(imageUrl)
|
|
? BoxFit.contain
|
|
: BoxFit.cover;
|
|
final portrait =
|
|
animation != null &&
|
|
!MediaQuery.disableAnimationsOf(context) &&
|
|
TickerMode.valuesOf(context).enabled
|
|
? ProgressiveAnimatedAvatar(
|
|
descriptor: animation,
|
|
fallback: fallback,
|
|
fit: portraitFit,
|
|
)
|
|
: AvatarImageContent(
|
|
imageUrl: poster,
|
|
preferThumbnail: true,
|
|
fallback: fallback,
|
|
fit: portraitFit,
|
|
);
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(Radii.card),
|
|
child: ColoredBox(
|
|
color: context.colors.surfaceContainerLow,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
if (poster != null && !MediaQuery.highContrastOf(context))
|
|
Positioned.fill(
|
|
child: ExcludeSemantics(
|
|
child: RepaintBoundary(
|
|
child: ShaderMask(
|
|
blendMode: BlendMode.dstIn,
|
|
shaderCallback: (bounds) => const LinearGradient(
|
|
begin: Alignment.topCenter,
|
|
end: Alignment.bottomCenter,
|
|
colors: [Colors.white, Colors.transparent],
|
|
stops: [0.05, 0.75],
|
|
).createShader(bounds),
|
|
child: Opacity(
|
|
opacity: 0.55,
|
|
child: ImageFiltered(
|
|
imageFilter: ImageFilter.blur(sigmaX: 24, sigmaY: 24),
|
|
child: Transform.scale(
|
|
scale: 1.8,
|
|
child: AvatarImageContent(
|
|
imageUrl: poster,
|
|
preferThumbnail: true,
|
|
fallback: const SizedBox.shrink(),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onOpen,
|
|
excludeFromSemantics: true,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(Grid.twelve),
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: Semantics(
|
|
container: true,
|
|
button: true,
|
|
label: [
|
|
'Open $name',
|
|
if (subtitle != null) subtitle,
|
|
if (isBestie) 'Your Bestie',
|
|
].join(', '),
|
|
onTap: onOpen,
|
|
child: ExcludeSemantics(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Expanded(
|
|
child: Center(
|
|
child: RepaintBoundary(
|
|
child: SizedBox.square(
|
|
dimension: 104,
|
|
child: AvatarClip(
|
|
isAgent: true,
|
|
child: portrait,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.center,
|
|
style: context.textTheme.titleSmall?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: Grid.half),
|
|
SizedBox(
|
|
height:
|
|
44 *
|
|
(MediaQuery.textScalerOf(context).scale(16) / 16)
|
|
.clamp(1, double.infinity),
|
|
child:
|
|
footer ??
|
|
Center(
|
|
child: ExcludeSemantics(
|
|
child: Text(
|
|
subtitle ?? '',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
textAlign: TextAlign.center,
|
|
style: context.textTheme.bodySmall?.copyWith(
|
|
color: context.colors.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (isBestie)
|
|
Positioned(
|
|
top: Grid.twelve,
|
|
right: Grid.twelve,
|
|
child: IgnorePointer(
|
|
child: ExcludeSemantics(
|
|
child: Icon(
|
|
Icons.star,
|
|
size: 18,
|
|
color: context.colors.onSurfaceVariant,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|