Skip to content

Commit 962b3fd

Browse files
klopez4212Terp
andauthored
Add avatar color backdrop to mobile agent creation (#9184)
Adds a blurred, saturated backdrop to mobile’s **Choose avatar** screen that crossfades with the selected avatar or emoji color. Enlarged artwork keeps the effect abstract; the upper fade leaves the bottom controls clear. Supports reduced motion and high contrast. Validated with analysis, the full mobile suite (4,518 passed), light/dark widget previews, and an iPhone Air install with the existing account preserved. ### Snapshots Flutter widget captures: | | Before | After | |---|---|---| | Light | ![Light before](https://github.com/user-attachments/assets/2293d06f-8744-4949-bb6c-10e3d9975c4b) | ![Light after](https://github.com/user-attachments/assets/cfe75783-d2fe-4672-a2bb-c4426ed59b4f) | | Dark | ![Dark before](https://github.com/user-attachments/assets/1b09e33a-1cdd-4054-8def-dd1bac0bc691) | ![Dark after](https://github.com/user-attachments/assets/6c903577-5cfd-4a87-9974-cbe8c9aeae60) | buzz-review-completed Signed-off-by: kenny lopez <[email protected]> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
1 parent 32997e2 commit 962b3fd

3 files changed

Lines changed: 246 additions & 26 deletions

File tree

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import 'dart:ui' as ui;
2+
3+
import 'package:flutter/material.dart';
4+
5+
import 'agent_avatar_picker.dart';
6+
7+
/// A soft artwork tint behind the avatar editor, matching desktop creation.
8+
class AgentAvatarBackdrop extends StatelessWidget {
9+
const AgentAvatarBackdrop({super.key, required this.selection});
10+
11+
final AgentAvatarSelection selection;
12+
13+
@override
14+
Widget build(BuildContext context) {
15+
if (MediaQuery.highContrastOf(context)) return const SizedBox.expand();
16+
return IgnorePointer(
17+
child: ExcludeSemantics(
18+
child: ClipRect(
19+
child: ShaderMask(
20+
blendMode: BlendMode.dstIn,
21+
shaderCallback: (bounds) => const LinearGradient(
22+
begin: Alignment.topCenter,
23+
end: Alignment.bottomCenter,
24+
// Keep the wash near the portrait; the lower controls sit clear.
25+
colors: [Colors.white, Color(0x66FFFFFF), Colors.transparent],
26+
stops: [0, 0.25, 0.68],
27+
).createShader(bounds),
28+
child: AnimatedSwitcher(
29+
duration: MediaQuery.disableAnimationsOf(context)
30+
? Duration.zero
31+
: const Duration(milliseconds: 240),
32+
layoutBuilder: (current, previous) => Stack(
33+
fit: StackFit.expand,
34+
children: [...previous, ?current],
35+
),
36+
child: RepaintBoundary(
37+
key: ValueKey((
38+
selection.url,
39+
selection.bytes,
40+
selection.color,
41+
)),
42+
child: Opacity(
43+
opacity: selection.emoji != null ? 0.14 : 0.64,
44+
child: ImageFiltered(
45+
imageFilter: ui.ImageFilter.blur(sigmaX: 40, sigmaY: 40),
46+
child: Transform.scale(
47+
// Crop into the artwork so it reads as abstract color.
48+
scale: 3.5,
49+
alignment: const Alignment(0, 0.12),
50+
child: selection.emoji != null
51+
? ColoredBox(color: Color(selection.color!))
52+
: ColorFiltered(
53+
// The desktop backdrop uses saturate(4).
54+
colorFilter: const ColorFilter.matrix([
55+
3.3622,
56+
-2.1456,
57+
-0.2166,
58+
0,
59+
0,
60+
-0.6378,
61+
1.8544,
62+
-0.2166,
63+
0,
64+
0,
65+
-0.6378,
66+
-2.1456,
67+
3.7834,
68+
0,
69+
0,
70+
0,
71+
0,
72+
0,
73+
1,
74+
0,
75+
]),
76+
child: selection.bytes != null
77+
? Image.memory(
78+
selection.bytes!,
79+
fit: BoxFit.cover,
80+
cacheWidth: 256,
81+
excludeFromSemantics: true,
82+
errorBuilder: (_, _, _) =>
83+
const SizedBox.expand(),
84+
)
85+
: Image.network(
86+
selection.url!,
87+
fit: BoxFit.cover,
88+
cacheWidth: 256,
89+
excludeFromSemantics: true,
90+
errorBuilder: (_, _, _) =>
91+
const SizedBox.expand(),
92+
),
93+
),
94+
),
95+
),
96+
),
97+
),
98+
),
99+
),
100+
),
101+
),
102+
);
103+
}
104+
}

‎mobile/lib/features/agents/agent_avatar_editor_page.dart‎

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '../../shared/theme/theme.dart';
55
import '../../shared/widgets/frosted_app_bar.dart';
66
import '../../shared/widgets/frosted_scaffold.dart';
77
import 'agent_avatar_choices.dart';
8+
import 'agent_avatar_backdrop.dart';
89
import 'agent_avatar_geometry.dart';
910
import 'agent_avatar_picker.dart';
1011

@@ -56,36 +57,43 @@ class AgentAvatarEditorPage extends HookWidget {
5657
),
5758
],
5859
),
59-
body: SafeArea(
60-
top: false,
61-
minimum: const EdgeInsets.only(bottom: Grid.gutter),
62-
child: Padding(
63-
padding: EdgeInsets.fromLTRB(
64-
Grid.gutter,
65-
frostedAppBarHeight(context) + Grid.xxs,
66-
Grid.gutter,
67-
Grid.sm,
60+
body: Stack(
61+
children: [
62+
Positioned.fill(
63+
child: AgentAvatarBackdrop(selection: selection.value),
6864
),
69-
child: LayoutBuilder(
70-
builder: (context, constraints) => SingleChildScrollView(
71-
clipBehavior: Clip.none,
72-
child: AgentAvatarPicker(
73-
// Fill the available height so the tray shares the page gutters.
74-
controlsHeight:
75-
(constraints.maxHeight -
76-
agentAvatarChoicesHeight(context) -
77-
Grid.sm -
78-
agentAvatarPreviewSpace)
79-
.clamp(180, double.infinity),
80-
selection: selection.value,
81-
heroTag: heroTag,
82-
onChanged: (value) => selection.value = value,
83-
disabled: false,
84-
onBusyChanged: (value) => busy.value = value,
65+
SafeArea(
66+
top: false,
67+
minimum: const EdgeInsets.only(bottom: Grid.gutter),
68+
child: Padding(
69+
padding: EdgeInsets.fromLTRB(
70+
Grid.gutter,
71+
frostedAppBarHeight(context) + Grid.xxs,
72+
Grid.gutter,
73+
Grid.sm,
74+
),
75+
child: LayoutBuilder(
76+
builder: (context, constraints) => SingleChildScrollView(
77+
clipBehavior: Clip.none,
78+
child: AgentAvatarPicker(
79+
// Fill the available height so the tray shares the page gutters.
80+
controlsHeight:
81+
(constraints.maxHeight -
82+
agentAvatarChoicesHeight(context) -
83+
Grid.sm -
84+
agentAvatarPreviewSpace)
85+
.clamp(180, double.infinity),
86+
selection: selection.value,
87+
heroTag: heroTag,
88+
onChanged: (value) => selection.value = value,
89+
disabled: false,
90+
onBusyChanged: (value) => busy.value = value,
91+
),
92+
),
8593
),
8694
),
8795
),
88-
),
96+
],
8997
),
9098
),
9199
);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import 'dart:convert';
2+
3+
import 'package:buzz/features/agents/agent_avatar_backdrop.dart';
4+
import 'package:buzz/features/agents/agent_avatar_picker.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
void main() {
9+
final png = base64Decode(
10+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=',
11+
);
12+
final first = AgentAvatarSelection.emoji(png, '😊', 0xFFFFCC00);
13+
final second = AgentAvatarSelection.emoji(png, '😊', 0xFF0090FF);
14+
15+
Widget host(
16+
AgentAvatarSelection selection, {
17+
bool reduced = false,
18+
bool contrast = false,
19+
}) => MaterialApp(
20+
home: MediaQuery(
21+
data: MediaQueryData(disableAnimations: reduced, highContrast: contrast),
22+
child: SizedBox(
23+
width: 390,
24+
height: 800,
25+
child: AgentAvatarBackdrop(selection: selection),
26+
),
27+
),
28+
);
29+
30+
testWidgets('rapid selection changes settle on the latest artwork tint', (
31+
tester,
32+
) async {
33+
await tester.pumpWidget(host(first));
34+
await tester.pumpWidget(host(second));
35+
await tester.pump(const Duration(milliseconds: 80));
36+
expect(
37+
find.descendant(
38+
of: find.byType(AgentAvatarBackdrop),
39+
matching: find.byType(ColoredBox),
40+
),
41+
findsNWidgets(2),
42+
);
43+
await tester.pumpWidget(host(first));
44+
await tester.pumpAndSettle();
45+
final colors = tester
46+
.widgetList<ColoredBox>(
47+
find.descendant(
48+
of: find.byType(AgentAvatarBackdrop),
49+
matching: find.byType(ColoredBox),
50+
),
51+
)
52+
.map((box) => box.color);
53+
expect(colors, [Color(first.color!)]);
54+
expect(tester.takeException(), isNull);
55+
});
56+
57+
testWidgets('reduced motion replaces the tint without a crossfade', (
58+
tester,
59+
) async {
60+
await tester.pumpWidget(host(first, reduced: true));
61+
await tester.pumpWidget(host(second, reduced: true));
62+
await tester.pump();
63+
expect(tester.binding.transientCallbackCount, 0);
64+
final colors = tester
65+
.widgetList<ColoredBox>(
66+
find.descendant(
67+
of: find.byType(AgentAvatarBackdrop),
68+
matching: find.byType(ColoredBox),
69+
),
70+
)
71+
.map((box) => box.color);
72+
expect(colors, [Color(second.color!)]);
73+
});
74+
75+
testWidgets(
76+
'decorative artwork cannot intercept taps or add image semantics',
77+
(tester) async {
78+
final semantics = tester.ensureSemantics();
79+
var taps = 0;
80+
await tester.pumpWidget(
81+
MaterialApp(
82+
home: Stack(
83+
children: [
84+
Positioned.fill(
85+
child: GestureDetector(
86+
onTap: () => taps++,
87+
child: const ColoredBox(color: Colors.white),
88+
),
89+
),
90+
Positioned.fill(
91+
child: AgentAvatarBackdrop(
92+
selection: AgentAvatarSelection.image(png),
93+
),
94+
),
95+
],
96+
),
97+
),
98+
);
99+
await tester.pumpAndSettle();
100+
await tester.tapAt(const Offset(100, 100));
101+
expect(taps, 1);
102+
expect(find.bySemanticsLabel('Selected agent avatar'), findsNothing);
103+
semantics.dispose();
104+
await tester.pumpWidget(host(first, contrast: true));
105+
expect(find.byType(ImageFiltered), findsNothing);
106+
},
107+
);
108+
}

0 commit comments

Comments
 (0)