feat(mobile): refresh onboarding and smooth QR scanner motion (#8019)

## Summary
Refresh mobile onboarding with light/dark gradients, an animated fuzzy
Buzz wordmark and tagline, and bottom-aligned glass/ghost actions.
Remove the dot grid and idle scroll bounce, and smooth the QR scanner's
continuous corners and spring transitions by deferring camera teardown
until dismissal finishes.

### Related issue
N/A — no matching mobile onboarding issue or PR found.

### Testing
- Mobile formatting, analysis, and full test suite passed at
`0bb357f7a`.
- Regression coverage includes shader animation/reduced motion, keyboard
reachability, scanner interruption, deferred camera disposal, and
rendered error contrast in both themes (mutation-checked).
- Signed iOS release build installed on iPhone Air; Kenneth tried the
onboarding and scanner during iteration and approved the final blur.
- Agent review completed with no correctness blockers. Android device
validation was not performed; hosted checks run separately.

buzz-review-completed

### Preview
Production-widget renders at 420 × 912; before: `5fdb2e536`, after:
`443858a96`.

| Before | After — light | After — dark |
|---|---|---|
|
![Before](https://raw.githubusercontent.com/block/buzz/52fb09e3c7e536f3a365d61401a077ce03ac47d9/pr-8019--buzz-before-light.png)
|
![Light](https://raw.githubusercontent.com/block/buzz/52fb09e3c7e536f3a365d61401a077ce03ac47d9/pr-8019--buzz-blur-only-light.png)
|
![Dark](https://raw.githubusercontent.com/block/buzz/52fb09e3c7e536f3a365d61401a077ce03ac47d9/pr-8019--buzz-blur-only-dark.png)
|

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
This commit is contained in:
klopez4212
2026-10-01 15:17:04 +01:00
committed by GitHub
parent 5fdb2e5365
commit 6b5bb6f5a3
16 changed files with 1078 additions and 210 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

View File

@@ -1,4 +1,6 @@
import 'dart:async';
import 'dart:math' show sqrt2;
import 'dart:ui' show ImageFilter;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -11,20 +13,15 @@ import '../../shared/security/sensitive_action_authorizer.dart';
import '../../shared/theme/theme.dart';
import '../../shared/widgets/buzz_loading_indicator.dart';
import '../../shared/widgets/ios_glass_navigation_button.dart';
import '../../shared/widgets/tappable_flapping_bee.dart';
import 'pairing_page/onboarding_wordmark.dart';
import 'pairing_provider.dart';
import 'pairing_qr_scanner.dart';
part 'pairing_page/onboarding_background.dart';
part 'pairing_page/onboarding_colors.dart';
part 'pairing_page/onboarding_glass_button.dart';
part 'pairing_page/pairing_welcome_view.dart';
const _onboardingChartreuse = Color(0xFFD7D72E);
const _onboardingShellBottom = Color(0xFFD7E7F6);
const _onboardingCtaLabel = Color(0xFFD7E6F0);
const _onboardingInk = Color(0xFF111111);
const _onboardingMutedInk = Color(0xB3111111);
const _onboardingErrorInk = Color(0xFF7A1025);
class PairingPage extends HookConsumerWidget {
/// When true, the pairing page is being used to add a new community
/// (user is already authenticated with at least one community).
@@ -88,12 +85,14 @@ class PairingPage extends HookConsumerWidget {
}
final isVerifyingSas = pairingState.status == PairingStatus.confirmingSas;
final onboardingSystemOverlayStyle = SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.transparent,
);
final onboardingSystemOverlayStyle =
(context._onboardingIsDark
? SystemUiOverlayStyle.light
: SystemUiOverlayStyle.dark)
.copyWith(statusBarColor: Colors.transparent);
final pairingAppBar = addingCommunity
? AppBar(
foregroundColor: _onboardingInk,
foregroundColor: context._onboardingInk,
systemOverlayStyle: onboardingSystemOverlayStyle,
leadingWidth: Theme.of(context).platform == TargetPlatform.iOS
? Grid.quarter + iosGlassChannelHeaderLeadingWidth
@@ -108,7 +107,7 @@ class PairingPage extends HookConsumerWidget {
onPressed: () => Navigator.of(context).maybePop(),
width: iosGlassChannelHeaderLeadingWidth,
buttonCenterX: iosGlassChannelHeaderButtonCenterX,
foregroundColor: _onboardingInk,
foregroundColor: context._onboardingInk,
),
)
: IconButton(
@@ -119,7 +118,7 @@ class PairingPage extends HookConsumerWidget {
title: Text(
identityRecoveryOnly ? 'Send to Desktop' : 'Add Community',
style: context.textTheme.titleMedium?.copyWith(
color: _onboardingInk,
color: context._onboardingInk,
),
),
)
@@ -162,9 +161,7 @@ class PairingPage extends HookConsumerWidget {
)
: AnnotatedRegion<SystemUiOverlayStyle>(
key: const Key('pairing-onboarding-system-overlay'),
value: SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.transparent,
),
value: onboardingSystemOverlayStyle,
child: _OnboardingBackground(
child: Scaffold(
backgroundColor: Colors.transparent,
@@ -254,7 +251,7 @@ class _SasVerificationView extends StatelessWidget {
'Confirm desktop code',
textAlign: TextAlign.center,
style: context.textTheme.headlineSmall?.copyWith(
color: _onboardingInk,
color: context._onboardingInk,
fontWeight: FontWeight.w600,
letterSpacing: -0.4,
),
@@ -266,7 +263,7 @@ class _SasVerificationView extends StatelessWidget {
: 'Make sure the six-digit code matches on both devices. Your Buzz identity will transfer to this device. Only continue if you started this pairing from your desktop.',
textAlign: TextAlign.center,
style: context.textTheme.bodyMedium?.copyWith(
color: _onboardingMutedInk,
color: context._onboardingMutedInk,
),
),
const SizedBox(height: Grid.md),
@@ -288,7 +285,7 @@ class _SasVerificationView extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: Grid.xs),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.7),
color: context._onboardingInputSurface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: context.colors.primary.withValues(alpha: 0.15),
@@ -298,7 +295,7 @@ class _SasVerificationView extends StatelessWidget {
sasCode[index],
style: context.textTheme.displaySmall?.copyWith(
fontWeight: FontWeight.w600,
color: _onboardingInk,
color: context._onboardingInk,
),
),
),
@@ -316,22 +313,22 @@ class _SasVerificationView extends StatelessWidget {
onChanged: confirmed
? null
: (value) => onProtectionChanged(value ?? false),
activeColor: _onboardingInk,
checkColor: _onboardingCtaLabel,
side: const BorderSide(color: _onboardingInk),
activeColor: context._onboardingInk,
checkColor: context._onboardingCtaLabel,
side: BorderSide(color: context._onboardingInk),
controlAffinity: ListTileControlAffinity.leading,
contentPadding: EdgeInsets.zero,
title: Text(
biometricLabel,
style: context.textTheme.bodyMedium?.copyWith(
color: _onboardingInk,
color: context._onboardingInk,
fontWeight: FontWeight.w600,
),
),
subtitle: Text(
'For secure actions',
style: context.textTheme.bodySmall?.copyWith(
color: _onboardingMutedInk,
color: context._onboardingMutedInk,
),
),
),
@@ -341,7 +338,7 @@ class _SasVerificationView extends StatelessWidget {
errorMessage!,
textAlign: TextAlign.center,
style: context.textTheme.bodySmall?.copyWith(
color: _onboardingErrorInk,
color: context._onboardingErrorInk,
),
),
],
@@ -354,14 +351,14 @@ class _SasVerificationView extends StatelessWidget {
children: [
BuzzLoadingIndicator(
size: 24,
color: _onboardingInk,
color: context._onboardingInk,
semanticLabel: 'Connecting',
),
const SizedBox(width: Grid.twelve),
Text(
'Confirmed — waiting for desktop',
style: context.textTheme.bodySmall?.copyWith(
color: _onboardingMutedInk,
color: context._onboardingMutedInk,
),
),
],
@@ -372,14 +369,14 @@ class _SasVerificationView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
FilledButton.icon(
style: _onboardingButtonStyle,
style: context._onboardingButtonStyle,
onPressed: onConfirm,
icon: const Icon(LucideIcons.check),
label: const Text('Codes match'),
),
const SizedBox(height: Grid.xxs),
TextButton(
style: _onboardingSecondaryButtonStyle.copyWith(
style: context._onboardingSecondaryButtonStyle.copyWith(
minimumSize: const WidgetStatePropertyAll(
Size.fromHeight(48),
),

View File

@@ -7,35 +7,87 @@ class _OnboardingBackground extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isDark = context._onboardingIsDark;
return DecoratedBox(
key: const Key('pairing-onboarding-background'),
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [_onboardingChartreuse, _onboardingShellBottom],
),
decoration: BoxDecoration(
color: isDark ? const Color(0xFF11181D) : const Color(0xFFE7F0EF),
image: isDark
? null
: const DecorationImage(
// Same supplied artwork and full-image stretch as Buzz 2.0.
image: AssetImage('assets/images/shell-gradient.png'),
fit: BoxFit.fill,
),
),
child: CustomPaint(
painter: _OnboardingShellPainter(isDark: isDark),
child: child,
),
child: CustomPaint(painter: const _DotGridPainter(), child: child),
);
}
}
class _DotGridPainter extends CustomPainter {
const _DotGridPainter();
class _OnboardingShellPainter extends CustomPainter {
final bool isDark;
const _OnboardingShellPainter({required this.isDark});
@override
void paint(Canvas canvas, Size size) {
final dotPaint = Paint()..color = _onboardingInk.withValues(alpha: 0.08);
const spacing = 24.0;
for (var x = 0.0; x <= size.width; x += spacing) {
for (var y = 0.0; y <= size.height; y += spacing) {
canvas.drawCircle(Offset(x, y), 1, dotPaint);
}
if (size.isEmpty) return;
if (isDark) {
// Match the desktop's layered CSS farthest-corner ellipses.
_paintGlow(
canvas,
size,
const Offset(0.9, 1),
0.7,
const Color(0xFF39304B),
);
_paintGlow(
canvas,
size,
const Offset(0.15, 0),
0.65,
const Color(0xFF203D53),
);
}
}
void _paintGlow(
Canvas canvas,
Size size,
Offset position,
double stop,
Color color,
) {
final radiusX =
(position.dx > 0.5 ? position.dx : 1 - position.dx) *
size.width *
sqrt2 *
stop;
final radiusY =
(position.dy > 0.5 ? position.dy : 1 - position.dy) *
size.height *
sqrt2 *
stop;
canvas.save();
canvas.clipRect(Offset.zero & size);
canvas.translate(position.dx * size.width, position.dy * size.height);
canvas.scale(radiusX, radiusY);
canvas.drawCircle(
Offset.zero,
1,
Paint()
..shader = RadialGradient(
colors: [color, color.withValues(alpha: 0)],
).createShader(const Rect.fromLTWH(-1, -1, 2, 2)),
);
canvas.restore();
}
@override
bool shouldRepaint(_DotGridPainter oldDelegate) => false;
bool shouldRepaint(_OnboardingShellPainter oldDelegate) =>
oldDelegate.isDark != isDark;
}

View File

@@ -0,0 +1,48 @@
part of '../pairing_page.dart';
// Foregrounds for the fixed Buzz shell artwork, independent of accent choice.
extension _OnboardingColors on BuildContext {
bool get _onboardingIsDark => Theme.of(this).brightness == Brightness.dark;
Color get _onboardingInk =>
_onboardingIsDark ? const Color(0xFFE6EDF0) : const Color(0xFF111111);
Color get _onboardingMutedInk =>
_onboardingIsDark ? const Color(0xFFAAB8C0) : const Color(0xB3111111);
Color get _onboardingCtaLabel =>
_onboardingIsDark ? const Color(0xFF172229) : const Color(0xFFD7E6F0);
Color get _onboardingErrorInk =>
_onboardingIsDark ? const Color(0xFFFFAAA0) : const Color(0xFF7A1025);
Color get _onboardingInputSurface => _onboardingIsDark
? const Color(0xFF233039)
: Colors.white.withValues(alpha: 0.7);
OutlineInputBorder get _inputBorder => OutlineInputBorder(
borderRadius: BorderRadius.circular(Radii.md),
borderSide: BorderSide(color: _onboardingInk.withValues(alpha: 0.18)),
);
ButtonStyle get _onboardingButtonStyle => FilledButton.styleFrom(
minimumSize: const Size(0, 48),
padding: const EdgeInsets.symmetric(
horizontal: Grid.lg,
vertical: Grid.twelve,
),
backgroundColor: _onboardingInk,
foregroundColor: _onboardingCtaLabel,
disabledBackgroundColor: _onboardingInk.withValues(alpha: 0.38),
disabledForegroundColor: _onboardingCtaLabel.withValues(alpha: 0.7),
shape: const StadiumBorder(),
);
ButtonStyle get _onboardingSecondaryButtonStyle => TextButton.styleFrom(
minimumSize: const Size(0, 44),
padding: const EdgeInsets.symmetric(
horizontal: Grid.md,
vertical: Grid.xxs,
),
backgroundColor: _onboardingInk.withValues(alpha: 0.1),
foregroundColor: _onboardingInk,
disabledBackgroundColor: _onboardingInk.withValues(alpha: 0.05),
disabledForegroundColor: _onboardingInk.withValues(alpha: 0.45),
shape: const StadiumBorder(),
);
}

View File

@@ -0,0 +1,78 @@
part of '../pairing_page.dart';
// Flutter adaptation of Buzz 2.0's glass-primary-interactive and ghost button.
// Keep the material together: glass-2 fill, blur-md, directional rim, glass-3
// interaction. Flutter's buttons retain focus, semantics, and disabled behavior.
extension _OnboardingActionStyles on BuildContext {
ButtonStyle get _onboardingGlassButtonStyle =>
_onboardingButtonStyle.copyWith(
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
foregroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? _onboardingInk.withValues(alpha: 0.45)
: _onboardingInk,
),
overlayColor: const WidgetStatePropertyAll(Colors.transparent),
side: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.focused)
? BorderSide(color: _onboardingInk, width: 2)
: BorderSide.none,
),
backgroundBuilder: (context, states, child) {
final active =
states.contains(WidgetState.hovered) ||
states.contains(WidgetState.pressed);
final dark = context._onboardingIsDark;
final fill = dark
? (active ? const Color(0xA81C1C1C) : const Color(0x851C1C1C))
: (active ? const Color(0x9EFFFFFF) : const Color(0x85FFFFFF));
return ClipRRect(
borderRadius: BorderRadius.circular(999),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 16, sigmaY: 16),
child: CustomPaint(
foregroundPainter: _GlassButtonRim(dark: dark),
child: ColoredBox(color: fill, child: child),
),
),
);
},
);
ButtonStyle get _onboardingGhostButtonStyle =>
_onboardingSecondaryButtonStyle.copyWith(
backgroundColor: const WidgetStatePropertyAll(Colors.transparent),
side: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.focused)
? BorderSide(color: _onboardingInk, width: 2)
: BorderSide.none,
),
);
}
class _GlassButtonRim extends CustomPainter {
final bool dark;
const _GlassButtonRim({required this.dark});
@override
void paint(Canvas canvas, Size size) {
final rect = (Offset.zero & size).deflate(0.5);
final paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..shader = LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: dark
? const [Color(0x2EFFFFFF), Color(0x0FFFFFFF)]
: const [Color(0x73FFFFFF), Color(0x1FFFFFFF)],
).createShader(rect);
canvas.drawRRect(
RRect.fromRectAndRadius(rect, Radius.circular(size.height / 2)),
paint,
);
}
@override
bool shouldRepaint(_GlassButtonRim oldDelegate) => oldDelegate.dark != dark;
}

View File

@@ -0,0 +1,158 @@
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// The website's animated noise/displacement treatment over the shared artwork.
class OnboardingWordmark extends StatefulWidget {
/// Optional tint for dark appearances; null keeps the original ink.
final Color? color;
/// Creates the animated welcome wordmark.
const OnboardingWordmark({super.key, this.color});
@override
State<OnboardingWordmark> createState() => _OnboardingWordmarkState();
}
class _OnboardingWordmarkState extends State<OnboardingWordmark>
with SingleTickerProviderStateMixin, WidgetsBindingObserver {
late final _animation = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 400),
);
ui.Image? _image;
ui.FragmentShader? _shader;
bool _loading = false;
bool _motionEnabled = false;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_motionEnabled =
!MediaQuery.disableAnimationsOf(context) &&
TickerMode.valuesOf(context).enabled;
if (_motionEnabled && !_loading) {
_loading = true;
_loadArtwork();
}
_syncAnimation();
}
Future<void> _loadArtwork() async {
ui.Image? image;
ui.FragmentShader? shader;
try {
final program = await ui.FragmentProgram.fromAsset(
'shaders/onboarding_wordmark.frag',
);
final bytes = await rootBundle.load('assets/images/buzz-wordmark.png');
final codec = await ui.instantiateImageCodec(
bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes),
);
try {
image = (await codec.getNextFrame()).image;
} finally {
codec.dispose();
}
shader = program.fragmentShader()..setImageSampler(0, image);
if (!mounted) {
image.dispose();
shader.dispose();
return;
}
setState(() {
_image = image;
_shader = shader;
});
_syncAnimation();
} catch (error) {
image?.dispose();
shader?.dispose();
// Keep the static artwork usable if a renderer cannot load the effect.
debugPrint('Could not load onboarding wordmark effect: $error');
}
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) => _syncAnimation();
void _syncAnimation() {
final lifecycle = WidgetsBinding.instance.lifecycleState;
final active = lifecycle == null || lifecycle == AppLifecycleState.resumed;
if (_motionEnabled && active && _shader != null) {
if (!_animation.isAnimating) _animation.repeat();
} else {
_animation.stop();
}
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
_animation.dispose();
_shader?.dispose();
_image?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Semantics(
label: 'Buzz',
image: true,
child: ExcludeSemantics(
child: RepaintBoundary(
child: _shader != null && _motionEnabled
? CustomPaint(
key: const Key('pairing-buzz-animated-texture'),
painter: _WordmarkPainter(
_shader!,
_animation,
widget.color ?? const Color(0xFF231E1E),
),
)
: Image.asset(
'assets/images/buzz-wordmark.png',
fit: BoxFit.contain,
color: widget.color,
colorBlendMode: BlendMode.srcIn,
filterQuality: FilterQuality.medium,
),
),
),
);
}
}
class _WordmarkPainter extends CustomPainter {
final ui.FragmentShader shader;
final Animation<double> animation;
final Color color;
_WordmarkPainter(this.shader, this.animation, this.color)
: super(repaint: animation);
@override
void paint(Canvas canvas, Size size) {
shader
..setFloat(0, size.width)
..setFloat(1, size.height)
..setFloat(2, animation.value)
..setFloat(3, color.r)
..setFloat(4, color.g)
..setFloat(5, color.b)
..setFloat(6, color.a);
canvas.drawRect(Offset.zero & size, Paint()..shader = shader);
}
@override
bool shouldRepaint(_WordmarkPainter oldDelegate) =>
shader != oldDelegate.shader || color != oldDelegate.color;
}

View File

@@ -26,54 +26,58 @@ class _PairingWelcomeView extends StatelessWidget {
? Duration.zero
: const Duration(milliseconds: 220);
return LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(
Grid.gutter,
Grid.sm,
Grid.gutter,
Grid.sm,
),
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight - (Grid.sm * 2),
),
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: Grid.gutter,
vertical: Grid.sm,
),
child: CustomScrollView(
// Stay fixed when the welcome content fits; allow only real overflow
// (such as the pairing form above the keyboard), with no rubber banding.
physics: const ClampingScrollPhysics(),
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 136,
height: 136,
alignment: Alignment.center,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Color(0x4DFFFFFF),
),
child: const TappableFlappingBee(
width: 76,
color: _onboardingInk,
Expanded(
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 320),
child: AspectRatio(
aspectRatio: 777 / 326,
child: OnboardingWordmark(
key: const Key('pairing-buzz-wordmark'),
color: context._onboardingIsDark
? context._onboardingInk
: null,
),
),
),
const SizedBox(height: Grid.xxs),
Text(
'Your people, your agents, your projects —\nall in one place.',
textAlign: TextAlign.center,
style: context.textTheme.bodyLarge?.copyWith(
color: context._onboardingInk,
),
),
],
),
),
),
const SizedBox(height: Grid.sm),
Text(
'Welcome to Buzz',
textAlign: TextAlign.center,
style: context.textTheme.headlineSmall?.copyWith(
color: _onboardingInk,
fontWeight: FontWeight.w600,
letterSpacing: -0.4,
),
),
const SizedBox(height: Grid.xxs),
const SizedBox(height: Grid.md),
Text(
'Scan the QR code from your desktop app\nor paste a pairing code to connect.',
textAlign: TextAlign.center,
style: context.textTheme.bodyMedium?.copyWith(
color: _onboardingMutedInk,
color: context._onboardingMutedInk,
),
),
const SizedBox(height: Grid.md),
const SizedBox(height: Grid.xs),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: SizedBox(
@@ -81,15 +85,15 @@ class _PairingWelcomeView extends StatelessWidget {
child: Column(
children: [
FilledButton(
style: _onboardingButtonStyle,
style: context._onboardingGlassButtonStyle,
onPressed: isBusy ? null : onScan,
child: isBusy && !pairingCodeExpanded
? const SizedBox(
? SizedBox(
width: 20,
height: 20,
child: BuzzLoadingIndicator(
size: 20,
color: _onboardingCtaLabel,
color: context._onboardingInk,
semanticLabel: 'Opening scanner',
),
)
@@ -97,7 +101,7 @@ class _PairingWelcomeView extends StatelessWidget {
),
const SizedBox(height: Grid.xxs),
TextButton(
style: _onboardingSecondaryButtonStyle,
style: context._onboardingGhostButtonStyle,
onPressed: isBusy ? null : onTogglePairingCode,
child: Text(
pairingCodeExpanded
@@ -127,30 +131,33 @@ class _PairingWelcomeView extends StatelessWidget {
TextField(
controller: codeController,
style: context.textTheme.bodyMedium
?.copyWith(color: _onboardingInk),
cursorColor: _onboardingInk,
?.copyWith(
color: context._onboardingInk,
),
cursorColor: context._onboardingInk,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white.withValues(
alpha: 0.7,
),
fillColor:
context._onboardingInputSurface,
hintText:
'nostrpair://... or buzz://...',
hintStyle: context.textTheme.bodyMedium
?.copyWith(
color: _onboardingMutedInk,
color:
context._onboardingMutedInk,
),
prefixIcon: const Icon(
prefixIcon: Icon(
LucideIcons.link,
color: _onboardingInk,
),
enabledBorder: _inputBorder,
disabledBorder: _inputBorder,
focusedBorder: _inputBorder.copyWith(
borderSide: const BorderSide(
color: _onboardingInk,
),
color: context._onboardingInk,
),
enabledBorder: context._inputBorder,
disabledBorder: context._inputBorder,
focusedBorder: context._inputBorder
.copyWith(
borderSide: BorderSide(
color: context._onboardingInk,
),
),
isDense: true,
),
autocorrect: false,
@@ -168,15 +175,16 @@ class _PairingWelcomeView extends StatelessWidget {
SizedBox(
width: double.infinity,
child: FilledButton(
style: _onboardingButtonStyle,
style:
context._onboardingGlassButtonStyle,
onPressed: isBusy ? null : onConnect,
child: isBusy
? const SizedBox(
? SizedBox(
width: 20,
height: 20,
child: BuzzLoadingIndicator(
size: 20,
color: _onboardingCtaLabel,
color: context._onboardingInk,
semanticLabel: 'Connecting',
),
)
@@ -226,36 +234,8 @@ class _PairingWelcomeView extends StatelessWidget {
],
),
),
);
},
],
),
);
}
}
final _inputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(Radii.md),
borderSide: BorderSide(color: _onboardingInk.withValues(alpha: 0.18)),
);
final _onboardingButtonStyle = FilledButton.styleFrom(
minimumSize: const Size(0, 48),
padding: const EdgeInsets.symmetric(
horizontal: Grid.lg,
vertical: Grid.twelve,
),
backgroundColor: _onboardingInk,
foregroundColor: _onboardingCtaLabel,
disabledBackgroundColor: _onboardingInk.withValues(alpha: 0.38),
disabledForegroundColor: _onboardingCtaLabel.withValues(alpha: 0.7),
shape: const StadiumBorder(),
);
final _onboardingSecondaryButtonStyle = TextButton.styleFrom(
minimumSize: const Size(0, 44),
padding: const EdgeInsets.symmetric(horizontal: Grid.md, vertical: Grid.xxs),
backgroundColor: _onboardingInk.withValues(alpha: 0.1),
foregroundColor: _onboardingInk,
disabledBackgroundColor: _onboardingInk.withValues(alpha: 0.05),
disabledForegroundColor: _onboardingInk.withValues(alpha: 0.45),
shape: const StadiumBorder(),
);

View File

@@ -4,6 +4,7 @@ import 'dart:ui' show lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';

View File

@@ -1,8 +1,9 @@
part of '../pairing_qr_scanner.dart';
const _dynamicIslandOpenDuration = Duration(milliseconds: 460);
const _dynamicIslandCloseDuration = Duration(milliseconds: 340);
const _dynamicIslandEaseOut = Cubic(0.16, 1, 0.3, 1);
// A smooth, non-bouncy spring inspired by Apple's public motion guidance;
// these are our timings, not private Dynamic Island animation constants.
const _dynamicIslandOpenDuration = Duration(milliseconds: 440);
const _dynamicIslandCloseDuration = Duration(milliseconds: 360);
class _DynamicIslandQrScannerPortal extends HookWidget {
const _DynamicIslandQrScannerPortal();
@@ -10,30 +11,23 @@ class _DynamicIslandQrScannerPortal extends HookWidget {
@override
Widget build(BuildContext context) {
final controller = useMemoized(MobileScannerController.new);
final animation = useAnimationController(
duration: _dynamicIslandOpenDuration,
reverseDuration: _dynamicIslandCloseDuration,
);
final animation = useAnimationController();
final isClosing = useState(false);
final canPop = useState(false);
final hasHandledResult = useRef(false);
final cameraMounted = useRef(false);
final reduceMotion = MediaQuery.disableAnimationsOf(context);
useEffect(() {
unawaited(_setDynamicIslandScannerStatusBarHidden(true));
if (reduceMotion) {
animation.value = 1;
} else {
unawaited(animation.forward());
}
return () {
unawaited(_setDynamicIslandScannerStatusBarHidden(false));
unawaited(controller.dispose());
};
}, [animation, controller, reduceMotion]);
}, [controller]);
Future<void> finish(String? result) async {
if (canPop.value) return;
canPop.value = true;
await WidgetsBinding.instance.endOfFrame;
if (context.mounted) {
@@ -41,23 +35,46 @@ class _DynamicIslandQrScannerPortal extends HookWidget {
}
}
Future<void> closePortal() async {
if (isClosing.value || hasHandledResult.value) {
return;
useEffect(() {
Future<void> transition() async {
final closing = isClosing.value;
final target = closing ? 0.0 : 1.0;
try {
if (reduceMotion) {
animation.value = target;
} else {
await animation
.animateWith(
SpringSimulation(
SpringDescription.withDurationAndBounce(
duration: closing
? _dynamicIslandCloseDuration
: _dynamicIslandOpenDuration,
bounce: 0,
),
animation.value,
target,
animation.velocity,
tolerance: const Tolerance(distance: 0.001, velocity: 0.02),
snapToEnd: true,
),
)
.orCancel;
}
if (closing && context.mounted) await finish(null);
} on TickerCanceled {
// A dismissal, motion-setting change, or unmount can retarget the spring.
}
}
unawaited(transition());
return null;
}, [animation, reduceMotion, isClosing.value]);
void closePortal() {
if (isClosing.value || hasHandledResult.value) return;
hasHandledResult.value = true;
isClosing.value = true;
canPop.value = true;
if (reduceMotion) {
animation.value = 0;
await WidgetsBinding.instance.endOfFrame;
} else {
await animation.reverse();
}
if (context.mounted) {
Navigator.of(context).pop();
}
}
void handleDetection(BarcodeCapture capture) {
@@ -78,7 +95,7 @@ class _DynamicIslandQrScannerPortal extends HookWidget {
canPop: canPop.value,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) {
unawaited(closePortal());
closePortal();
}
},
child: Material(
@@ -108,23 +125,26 @@ class _DynamicIslandQrScannerPortal extends HookWidget {
AnimatedBuilder(
animation: animation,
builder: (context, _) {
final progress = _dynamicIslandEaseOut.transform(
animation.value.clamp(0.0, 1.0),
);
final progress = animation.value.clamp(0.0, 1.0);
final frame = geometry.frameAt(progress);
final scannerOpacity = geometry.scannerOpacityAt(
progress,
);
// Once revealed, keep the camera mounted until the route
// closes. Native camera teardown can stall a moving frame.
if (scannerOpacity > 0) cameraMounted.value = true;
final introLabelOpacity = isClosing.value
? 0.0
: geometry.introLabelOpacityAt(progress);
final promptOpacity = isClosing.value
? 0.0
: math.max(introLabelOpacity, scannerOpacity);
final promptOpacity = math.max(
introLabelOpacity,
scannerOpacity,
);
return Positioned.fromRect(
rect: frame,
child: ClipRRect(
// Continuous corners stay smooth throughout the island morph.
child: ClipRSuperellipse(
key: const ValueKey(
'dynamic-island-qr-scanner-portal',
),
@@ -136,7 +156,7 @@ class _DynamicIslandQrScannerPortal extends HookWidget {
child: Stack(
fit: StackFit.expand,
children: [
if (!isClosing.value && scannerOpacity > 0)
if (cameraMounted.value)
Opacity(
opacity: scannerOpacity,
child: _QrScannerCamera(

View File

@@ -66,8 +66,12 @@ dev_dependencies:
flutter:
uses-material-design: true
shaders:
- shaders/onboarding_wordmark.frag
assets:
- assets/images/buzz-icon.png
- assets/images/shell-gradient.png
- assets/images/buzz-wordmark.png
# Generated by `just mobile-emoji-data` from the same emoji-mart dataset
# desktop uses. Do not hand-edit.
- assets/emoji/emoji-data.json

View File

@@ -0,0 +1,71 @@
#include <flutter/runtime_effect.glsl>
uniform vec2 uSize;
uniform float uPhase;
uniform vec4 uColor;
uniform sampler2D uWordmark;
out vec4 fragColor;
float hash(vec2 p, float seed) {
return fract(sin(dot(p, vec2(127.1, 311.7)) + seed * 17.0) * 43758.5453);
}
float noise(vec2 p, float seed) {
vec2 cell = floor(p);
vec2 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(hash(cell, seed), hash(cell + vec2(1, 0), seed), f.x),
mix(hash(cell + vec2(0, 1), seed), hash(cell + vec2(1, 1), seed), f.x), f.y);
}
float fractalNoise(vec2 p, float seed) {
float value = 0.0;
float weight = 0.5333333;
for (int i = 0; i < 4; i++) {
value += weight * noise(p, seed);
p *= 2.0;
weight *= 0.5;
}
return value;
}
float seedAt(float step) {
if (step < 1.0) return 7.0;
if (step < 2.0) return 19.0;
if (step < 3.0) return 11.0;
if (step < 4.0) return 25.0;
return 7.0;
}
// A small Gaussian kernel broadens the fuzzy edge at phone size without
// adding a separate blur pass or softening the surrounding onboarding UI.
float softAlpha(vec2 uv) {
vec2 d = vec2(9.0) / vec2(777.0, 326.0);
float alpha = texture(uWordmark, uv).a * 0.25;
alpha += (texture(uWordmark, uv + vec2(d.x, 0.0)).a
+ texture(uWordmark, uv - vec2(d.x, 0.0)).a
+ texture(uWordmark, uv + vec2(0.0, d.y)).a
+ texture(uWordmark, uv - vec2(0.0, d.y)).a) * 0.125;
alpha += (texture(uWordmark, uv + d).a
+ texture(uWordmark, uv - d).a
+ texture(uWordmark, uv + vec2(d.x, -d.y)).a
+ texture(uWordmark, uv + vec2(-d.x, d.y)).a) * 0.0625;
return alpha;
}
void main() {
vec2 uv = FlutterFragCoord().xy / uSize;
vec2 p = uv * vec2(777.0, 326.0) * 0.68;
float phase = uPhase * 4.0;
float a = seedAt(floor(phase));
float b = seedAt(floor(phase) + 1.0);
float blend = smoothstep(0.0, 1.0, fract(phase));
vec2 textureNoise = mix(
vec2(fractalNoise(p, a), fractalNoise(p + 43.7, a)),
vec2(fractalNoise(p, b), fractalNoise(p + 43.7, b)), blend);
vec2 displaced = uv + (textureNoise - 0.5) * 14.4 / vec2(777.0, 326.0);
float alpha = softAlpha(clamp(displaced, 0.0, 1.0));
float grain = clamp((textureNoise.x + textureNoise.y) * 0.99, 0.0, 1.0);
alpha = (alpha + alpha * grain * (1.0 - alpha)) * uColor.a;
fragColor = vec4(uColor.rgb * alpha, alpha);
}

View File

@@ -0,0 +1,105 @@
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:buzz/features/pairing/pairing_page/onboarding_wordmark.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'animates texture, pauses in background, and respects reduced motion',
(tester) async {
Future<void> show({
bool reduceMotion = false,
bool visible = true,
}) async {
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: MediaQueryData(disableAnimations: reduceMotion),
child: TickerMode(
enabled: visible,
child: const Center(
child: SizedBox(
width: 320,
height: 320 * 326 / 777,
child: RepaintBoundary(
key: Key('capture'),
child: OnboardingWordmark(),
),
),
),
),
),
),
);
}
await show();
final texture = find.byKey(const Key('pairing-buzz-animated-texture'));
for (
var attempt = 0;
attempt < 100 && texture.evaluate().isEmpty;
attempt++
) {
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 20)),
);
await tester.pump();
}
expect(
texture,
findsOneWidget,
reason: 'Exercise the real compiled shader',
);
expect(find.bySemanticsLabel('Buzz'), findsOneWidget);
Future<Uint8List> pixels() async {
return (await tester.runAsync(() async {
final boundary = tester.renderObject<RenderRepaintBoundary>(
find.byKey(const Key('capture')),
);
final image = await boundary.toImage();
try {
final data = await image.toByteData(
format: ui.ImageByteFormat.rawRgba,
);
return Uint8List.fromList(data!.buffer.asUint8List());
} finally {
image.dispose();
}
}))!;
}
final first = await pixels();
await tester.pump(const Duration(milliseconds: 100));
expect(await pixels(), isNot(orderedEquals(first)));
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
await tester.pump();
final paused = await pixels();
await tester.pump(const Duration(milliseconds: 150));
expect(await pixels(), orderedEquals(paused));
expect(tester.binding.hasScheduledFrame, isFalse);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(await pixels(), isNot(orderedEquals(paused)));
await show(reduceMotion: true);
await tester.pumpAndSettle();
expect(texture, findsNothing);
expect(find.byType(Image), findsOneWidget);
expect(tester.binding.hasScheduledFrame, isFalse);
await show(visible: false);
await tester.pumpAndSettle();
expect(texture, findsNothing);
expect(tester.binding.hasScheduledFrame, isFalse);
await tester.pumpWidget(const SizedBox());
expect(tester.takeException(), isNull);
},
);
}

View File

@@ -1,4 +1,7 @@
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -6,13 +9,13 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:local_auth/local_auth.dart';
import 'package:lucide_icons_flutter/lucide_icons.dart';
import 'package:buzz/features/pairing/pairing_page.dart';
import 'package:buzz/features/pairing/pairing_page/onboarding_wordmark.dart';
import 'package:buzz/features/pairing/pairing_provider.dart';
import 'package:buzz/shared/community/community.dart';
import 'package:buzz/shared/security/sensitive_action_authorizer.dart';
import 'package:buzz/shared/theme/theme.dart';
import 'package:buzz/shared/widgets/buzz_loading_indicator.dart';
import 'package:buzz/shared/widgets/ios_glass_navigation_button.dart';
import 'package:buzz/shared/widgets/tappable_flapping_bee.dart';
import '../../helpers/widget_helpers.dart';
@@ -25,8 +28,14 @@ void main() {
WidgetHelpers.testable(child: const PairingPage()),
);
expect(find.byType(TappableFlappingBee), findsOneWidget);
expect(find.text('Welcome to Buzz'), findsOneWidget);
expect(find.bySemanticsLabel('Buzz'), findsOneWidget);
expect(find.text('Welcome to Buzz'), findsNothing);
expect(
find.text(
'Your people, your agents, your projects —\nall in one place.',
),
findsOneWidget,
);
expect(find.text('Scan a QR code'), findsOneWidget);
expect(find.text('Use pairing code'), findsOneWidget);
expect(find.text('Connect'), findsNothing);
@@ -47,11 +56,75 @@ void main() {
find.widgetWithText(TextButton, 'Use pairing code'),
);
final glassFinder = find.widgetWithText(FilledButton, 'Scan a QR code');
expect(
find.descendant(of: glassFinder, matching: find.byType(BackdropFilter)),
findsOneWidget,
);
expect(scanButton.height, greaterThanOrEqualTo(44));
expect(pairingCodeButton.height, greaterThanOrEqualTo(44));
expect(
tester
.widget<TextButton>(
find.widgetWithText(TextButton, 'Use pairing code'),
)
.style!
.backgroundColor!
.resolve({}),
Colors.transparent,
);
expect(scanButton.width, lessThan(440));
expect(pairingCodeButton.width, lessThan(440));
expect(find.byType(OutlinedButton), findsNothing);
});
testWidgets(
'docks welcome actions and keeps pairing reachable with keyboard',
(tester) async {
tester.view.devicePixelRatio = 1;
tester.view.physicalSize = const Size(390, 844);
tester.view.padding = const FakeViewPadding(top: 59, bottom: 34);
addTearDown(tester.view.reset);
await tester.pumpWidget(
WidgetHelpers.testable(
child: const PairingPage(),
disableAnimations: true,
),
);
final toggle = find.widgetWithText(TextButton, 'Use pairing code');
expect(tester.getBottomLeft(toggle).dy, 844 - 34 - Grid.sm);
expect(
tester
.getBottomLeft(find.byKey(const Key('pairing-buzz-wordmark')))
.dy,
lessThan(tester.getTopLeft(toggle).dy - 150),
);
final wordmark = find.byKey(const Key('pairing-buzz-wordmark'));
final originalFrame = tester.getRect(wordmark);
for (final distance in [-150.0, 150.0]) {
await tester.drag(find.byType(CustomScrollView), Offset(0, distance));
await tester.pump(const Duration(milliseconds: 100));
expect(tester.getRect(wordmark), originalFrame);
expect(tester.getBottomLeft(toggle).dy, 844 - 34 - Grid.sm);
}
await _expandPairingCode(tester);
tester.view.physicalSize = const Size(360, 560);
tester.view.viewInsets = const FakeViewPadding(bottom: 240);
await tester.pump();
await tester.enterText(find.byType(TextField), 'pairing-code-draft');
final connect = find.widgetWithText(FilledButton, 'Connect');
await tester.ensureVisible(connect);
await tester.pump();
expect(connect.hitTestable(), findsOneWidget);
expect(tester.getBottomLeft(connect).dy, lessThanOrEqualTo(560 - 240));
expect(find.text('pairing-code-draft'), findsOneWidget);
expect(tester.takeException(), isNull);
},
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
);
testWidgets('uses dark status-bar icons on the onboarding surface', (
tester,
) async {
@@ -67,6 +140,93 @@ void main() {
expect(overlay.value.statusBarColor, Colors.transparent);
});
testWidgets(
'switches welcome artwork and readable controls with appearance',
(tester) async {
Future<void> show(Brightness brightness) async {
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
theme: brightness == Brightness.dark
? AppTheme.dark()
: AppTheme.light(),
home: const PairingPage(),
),
),
);
await tester.pump(const Duration(milliseconds: 300));
}
await show(Brightness.light);
var decoration =
tester
.widget<DecoratedBox>(
find.byKey(const Key('pairing-onboarding-background')),
)
.decoration
as BoxDecoration;
expect(
(decoration.image!.image as AssetImage).assetName,
'assets/images/shell-gradient.png',
);
expect(decoration.image!.fit, BoxFit.fill);
await _expandPairingCode(tester);
await tester.enterText(find.byType(TextField), 'pairing-code-draft');
await show(Brightness.dark);
decoration =
tester
.widget<DecoratedBox>(
find.byKey(const Key('pairing-onboarding-background')),
)
.decoration
as BoxDecoration;
expect(decoration.image, isNull);
expect(decoration.color, const Color(0xFF11181D));
expect(
tester
.widget<OnboardingWordmark>(
find.byKey(const Key('pairing-buzz-wordmark')),
)
.color,
const Color(0xFFE6EDF0),
);
expect(
tester.widget<TextField>(find.byType(TextField)).style!.color,
const Color(0xFFE6EDF0),
);
expect(
tester
.widget<TextField>(find.byType(TextField))
.decoration!
.fillColor,
const Color(0xFF233039),
);
expect(find.text('pairing-code-draft'), findsOneWidget);
expect(
tester
.widget<AnnotatedRegion<SystemUiOverlayStyle>>(
find.byKey(const Key('pairing-onboarding-system-overlay')),
)
.value
.statusBarIconBrightness,
Brightness.light,
);
await show(Brightness.light);
expect(
tester
.widget<OnboardingWordmark>(
find.byKey(const Key('pairing-buzz-wordmark')),
)
.color,
isNull,
);
expect(find.text('pairing-code-draft'), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets('uses the onboarding surface for dark-theme SAS verification', (
tester,
) async {
@@ -83,18 +243,14 @@ void main() {
find.byKey(const Key('pairing-sas-system-overlay')),
);
expect(overlay.value.statusBarIconBrightness, Brightness.dark);
expect(overlay.value.statusBarIconBrightness, Brightness.light);
expect(overlay.value.statusBarColor, Colors.transparent);
final background = tester.widget<DecoratedBox>(
find.byKey(const Key('pairing-onboarding-background')),
);
final backgroundDecoration = background.decoration as BoxDecoration;
final backgroundGradient =
backgroundDecoration.gradient! as LinearGradient;
expect(backgroundGradient.colors, const [
Color(0xFFD7D72E),
Color(0xFFD7E7F6),
]);
expect(backgroundDecoration.color, const Color(0xFF11181D));
expect(backgroundDecoration.image, isNull);
expect(
tester.widget<Scaffold>(find.byType(Scaffold)).backgroundColor,
Colors.transparent,
@@ -284,6 +440,8 @@ void main() {
await _expandPairingCode(tester);
await tester.enterText(find.byType(TextField), 'nostrpair://ordinary');
await tester.ensureVisible(find.text('Connect'));
await tester.pump();
await tester.tap(find.text('Connect'));
await tester.pump();
@@ -306,6 +464,8 @@ void main() {
await _expandPairingCode(tester);
const code = 'nostrpair://desktop?mode=recover';
await tester.enterText(find.byType(TextField), code);
await tester.ensureVisible(find.text('Connect'));
await tester.pump();
await tester.tap(find.text('Connect'));
await tester.pump();
@@ -464,9 +624,9 @@ void main() {
);
}
const onboardingInk = Color(0xFF111111);
const onboardingMutedInk = Color(0xB3111111);
const onboardingCtaLabel = Color(0xFFD7E6F0);
const onboardingInk = Color(0xFFE6EDF0);
const onboardingMutedInk = Color(0xFFAAB8C0);
const onboardingCtaLabel = Color(0xFF172229);
final theme = AppTheme.dark();
final protectionTile = tester.widget<CheckboxListTile>(
find.byKey(const Key('protect-sensitive-actions-checkbox')),
@@ -482,7 +642,7 @@ void main() {
final firstDigitContainer = tester.widget<Container>(digitFinders.first);
final firstDigitDecoration =
firstDigitContainer.decoration! as BoxDecoration;
expect(firstDigitDecoration.color, Colors.white.withValues(alpha: 0.7));
expect(firstDigitDecoration.color, const Color(0xFF233039));
expect(
(firstDigitDecoration.border! as Border).top.color,
theme.colorScheme.primary.withValues(alpha: 0.15),
@@ -558,14 +718,13 @@ void main() {
);
});
testWidgets('uses accessible SAS error contrast in both themes', (
tester,
) async {
const errorMessage = 'Identity confirmation failed. Nothing transferred.';
const errorInk = Color(0xFF7A1025);
const gradientColors = [Color(0xFFD7D72E), Color(0xFFD7E7F6)];
for (final theme in [AppTheme.light(), AppTheme.dark()]) {
for (final brightness in Brightness.values) {
testWidgets('uses accessible SAS error contrast in ${brightness.name}', (
tester,
) async {
const errorMessage =
'Identity confirmation failed. Nothing transferred.';
final isDark = brightness == Brightness.dark;
await tester.pumpWidget(
ProviderScope(
overrides: [
@@ -573,21 +732,104 @@ void main() {
() => _ConfirmingSasPairingNotifier(errorMessage: errorMessage),
),
],
child: MaterialApp(theme: theme, home: const PairingPage()),
child: MaterialApp(
theme: isDark ? AppTheme.dark() : AppTheme.light(),
home: const PairingPage(),
),
),
);
await tester.pumpAndSettle();
final errorText = tester.widget<Text>(find.text(errorMessage));
expect(errorText.style?.color, errorInk);
for (final background in gradientColors) {
final errorFinder = find.text(errorMessage);
expect(Theme.of(tester.element(errorFinder)).brightness, brightness);
final errorInk = tester.widget<Text>(errorFinder).style!.color!;
expect(
errorInk,
isDark ? const Color(0xFFFFAAA0) : const Color(0xFF7A1025),
);
final backgroundFinder = find.byKey(
const Key('pairing-onboarding-background'),
);
final background = tester.widget<DecoratedBox>(backgroundFinder);
final decoration = background.decoration as BoxDecoration;
expect(
decoration.color,
isDark ? const Color(0xFF11181D) : const Color(0xFFE7F0EF),
);
if (isDark) {
expect(decoration.image, isNull);
} else {
expect(
_contrastRatio(errorInk, background),
greaterThanOrEqualTo(4.5),
(decoration.image!.image as AssetImage).assetName,
'assets/images/shell-gradient.png',
);
await tester.runAsync(
() => precacheImage(
decoration.image!.image,
tester.element(backgroundFinder),
),
);
}
final size = tester.getSize(backgroundFinder);
final errorRect = tester
.getRect(errorFinder)
.shift(-tester.getTopLeft(backgroundFinder));
// Render the production decoration and painter without foreground
// content, so sampled pixels are the actual surface behind the error.
const captureKey = Key('sas-error-background-capture');
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: RepaintBoundary(
key: captureKey,
child: SizedBox.fromSize(
size: size,
child: DecoratedBox(
decoration: decoration,
child: CustomPaint(
painter: (background.child! as CustomPaint).painter,
),
),
),
),
),
);
await tester.pumpAndSettle();
final boundary = tester.renderObject<RenderRepaintBoundary>(
find.byKey(captureKey),
);
await tester.runAsync(() async {
final image = await boundary.toImage(pixelRatio: 1);
try {
final pixels = (await image.toByteData(
format: ui.ImageByteFormat.rawRgba,
))!;
for (var y = errorRect.top.ceil(); y < errorRect.bottom; y += 4) {
for (var x = errorRect.left.ceil(); x < errorRect.right; x += 4) {
final offset = (y * image.width + x) * 4;
expect(pixels.getUint8(offset + 3), 255);
final surface = Color.fromARGB(
255,
pixels.getUint8(offset),
pixels.getUint8(offset + 1),
pixels.getUint8(offset + 2),
);
expect(
_contrastRatio(errorInk, surface),
greaterThanOrEqualTo(4.5),
reason: '${brightness.name} error contrast at ($x, $y)',
);
}
}
} finally {
image.dispose();
}
});
expect(tester.takeException(), isNull);
}
});
});
}
testWidgets('keeps SAS actions above the keyboard on small screens', (
tester,
@@ -641,8 +883,11 @@ double _contrastRatio(Color foreground, Color background) {
}
Future<void> _expandPairingCode(WidgetTester tester) async {
await tester.ensureVisible(find.text('Use pairing code'));
await tester.pump();
await tester.tap(find.text('Use pairing code'));
await tester.pumpAndSettle();
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
}
class _ErrorPairingNotifier extends Notifier<PairingState>

View File

@@ -164,8 +164,31 @@ void main() {
const ValueKey('dynamic-island-qr-scanner-portal'),
);
expect(tester.getRect(portal), const Rect.fromLTWH(136.5, 11, 120, 36));
expect(
tester.widget<ClipRSuperellipse>(portal).borderRadius,
BorderRadius.circular(18),
);
expect(
tester.widget<ClipRSuperellipse>(portal).clipBehavior,
Clip.antiAlias,
);
await tester.pump(const Duration(milliseconds: 460));
await tester.pump(const Duration(milliseconds: 16));
final firstOpeningFrame = tester.getRect(portal);
expect(firstOpeningFrame.height, inExclusiveRange(36, 50));
await tester.pump(const Duration(milliseconds: 214));
final openingRadius =
(tester.widget<ClipRSuperellipse>(portal).borderRadius
as BorderRadius)
.topLeft
.x;
expect(openingRadius, inExclusiveRange(18, 40));
await tester.pumpAndSettle();
expect(
tester.widget<ClipRSuperellipse>(portal).borderRadius,
BorderRadius.circular(40),
);
expect(tester.getRect(portal).top, 11);
expect(
find.byKey(const ValueKey('dynamic-island-qr-scanner-close')),
@@ -175,15 +198,93 @@ void main() {
await tester.tapAt(const Offset(196.5, 700));
await tester.pump();
expect(scannerClosed, isFalse);
expect(find.byType(MobileScanner), findsOneWidget);
await tester.pump(const Duration(milliseconds: 340));
await tester.pump(const Duration(milliseconds: 100));
final earlyClosingHeight = tester.getRect(portal).height;
expect(earlyClosingHeight, lessThan(280));
expect(find.byType(MobileScanner), findsOneWidget);
await tester.pump(const Duration(milliseconds: 200));
final lateClosingHeight = tester.getRect(portal).height;
// The camera is transparent here, but must not shut down mid-collapse.
expect(find.byType(MobileScanner), findsOneWidget);
expect(
tester
.widget<Opacity>(
find
.ancestor(
of: find.byType(MobileScanner),
matching: find.byType(Opacity),
)
.first,
)
.opacity,
0,
);
expect(fakeScannerPlatform.stopCalls, 0);
expect(fakeScannerPlatform._isDisposed, isFalse);
expect(lateClosingHeight, lessThan(earlyClosingHeight));
expect(lateClosingHeight, greaterThan(36));
// The final approach is slower than the initial collapse, not an impact.
expect(lateClosingHeight - 36, lessThan((363 - earlyClosingHeight) / 4));
final closingRadius =
(tester.widget<ClipRSuperellipse>(portal).borderRadius
as BorderRadius)
.topLeft
.x;
expect(closingRadius, inExclusiveRange(18, 40));
await tester.pump(const Duration(milliseconds: 170));
await tester.pumpAndSettle();
expect(scannerClosed, isTrue);
expect(portal, findsNothing);
expect(fakeScannerPlatform._isDisposed, isTrue);
debugDefaultTargetPlatformOverride = null;
},
);
testWidgets(
'an early dismissal keeps its frame and settles back into the island',
(tester) async {
await tester.binding.setSurfaceSize(const Size(393, 852));
addTearDown(() => tester.binding.setSurfaceSize(null));
var closeCount = 0;
await tester.pumpWidget(
MaterialApp(
home: Builder(
builder: (context) => TextButton(
onPressed: () async {
await showDynamicIslandPairingQrScanner(context);
closeCount++;
},
child: const Text('Open scanner'),
),
),
),
);
await tester.tap(find.text('Open scanner'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 80));
final portal = find.byKey(
const ValueKey('dynamic-island-qr-scanner-portal'),
);
final beforeDismissal = tester.getRect(portal);
await tester.tapAt(const Offset(196.5, 700));
await tester.pump();
expect(tester.getRect(portal), beforeDismissal);
// Preserve the outgoing velocity briefly instead of abruptly flipping it.
await tester.pump(const Duration(milliseconds: 8));
final afterDismissal = tester.getRect(portal);
expect(afterDismissal.height, greaterThan(beforeDismissal.height));
expect(afterDismissal.height - beforeDismissal.height, lessThan(12));
await tester.tapAt(const Offset(196.5, 700));
await tester.pumpAndSettle();
expect(closeCount, 1);
expect(portal, findsNothing);
expect(find.text('Open scanner'), findsOneWidget);
expect(tester.takeException(), isNull);
},
);
testWidgets('tapping the scanner closes it without a separate control', (
tester,
) async {
@@ -225,6 +326,10 @@ void main() {
const ValueKey('dynamic-island-qr-scanner-portal'),
);
expect(tester.getRect(portal), const Rect.fromLTWH(15, 11, 363, 363));
expect(
tester.widget<ClipRSuperellipse>(portal).borderRadius,
BorderRadius.circular(40),
);
await tester.tapAt(tester.getCenter(portal));
await tester.pump();
@@ -239,6 +344,7 @@ void main() {
class _FakeMobileScannerPlatform extends MobileScannerPlatform {
final _barcodes = StreamController<BarcodeCapture?>.broadcast();
var _isDisposed = false;
var stopCalls = 0;
@override
Stream<BarcodeCapture?> get barcodesStream => _barcodes.stream;
@@ -264,7 +370,9 @@ class _FakeMobileScannerPlatform extends MobileScannerPlatform {
Widget buildCameraView() => const SizedBox.expand();
@override
Future<void> stop() async {}
Future<void> stop() async {
stopCalls++;
}
@override
Future<void> dispose() async {

View File

@@ -24,7 +24,8 @@ void main() {
),
);
await tester.pump();
expect(find.text('Welcome to Buzz'), findsOneWidget);
expect(find.bySemanticsLabel('Buzz'), findsOneWidget);
expect(find.text('Scan a QR code'), findsOneWidget);
});
}