Update mobile toast animations (#8855)

Updates mobile toast animations and styling.



| Sign in | Retry | Copied |
| --- | --- | --- |
| ![Reconnect to
Builderlab](https://github.com/user-attachments/assets/5298b507-df5b-49da-a021-03f337e997fa)
| ![Save error with
Retry](https://github.com/user-attachments/assets/492c8929-4f91-4342-943b-a72b96547992)
| ![Copied
confirmation](https://github.com/user-attachments/assets/864fd629-7414-415e-81ef-5f7d3d5333a4)
|

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
This commit is contained in:
klopez4212
2026-10-31 14:50:00 +00:00
committed by GitHub
parent 5f13984a19
commit cfcaef4e9f
59 changed files with 1479 additions and 341 deletions

View File

@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'widgets/buzz_toast.dart';
Future<void> copyToClipboard(
BuildContext context,
String text, {
String message = 'Copied to clipboard',
String message = 'Copied',
}) async {
await Clipboard.setData(ClipboardData(text: text));
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(message), duration: const Duration(seconds: 2)),
);
showBuzzToast(context, message, kind: ToastKind.success);
}

View File

@@ -1,3 +1,4 @@
import 'package:buzz/shared/widgets/feedback_snackbar.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:buzz/shared/theme/buzz_icons.dart';
@@ -19,8 +20,9 @@ void showRemindMeLaterSheet({
final service = ref.read(reminderServiceProvider);
final messenger = ScaffoldMessenger.of(context);
if (service == null) {
messenger.showSnackBar(
messenger.showFeedbackSnackBar(
const SnackBar(content: Text('Sign in to set reminders')),
kind: ToastKind.generic,
);
return;
}
@@ -28,12 +30,16 @@ void showRemindMeLaterSheet({
Future<void> submit(int notBefore) async {
try {
await service.createReminder(target: target, notBefore: notBefore);
messenger.showSnackBar(const SnackBar(content: Text('Reminder set')));
messenger.showFeedbackSnackBar(
const SnackBar(content: Text('Reminder set')),
kind: ToastKind.success,
);
} catch (error) {
// Stable user-facing copy; the relay/crypto detail goes to the log.
debugPrint('[RemindMeLater] createReminder failed: $error');
messenger.showSnackBar(
messenger.showFeedbackSnackBar(
const SnackBar(content: Text('Couldn’t set reminder. Try again.')),
kind: ToastKind.error,
);
}
}
@@ -119,9 +125,10 @@ Future<int?> _pickCustomDateTime(BuildContext context) async {
final timestamp = combineCustomDateTime(date, time.hour, time.minute);
if (timestamp == null && context.mounted) {
ScaffoldMessenger.of(
context,
).showSnackBar(const SnackBar(content: Text('Pick a time in the future')));
ScaffoldMessenger.of(context).showFeedbackSnackBar(
const SnackBar(content: Text('Pick a time in the future')),
kind: ToastKind.error,
);
}
return timestamp;
}

View File

@@ -343,11 +343,24 @@ class AppTheme {
space: 1,
),
// Snackbar
// Shared feedback surface for success, errors, and clipboard notices.
snackBarTheme: SnackBarThemeData(
behavior: SnackBarBehavior.floating,
backgroundColor: scheme.inverseSurface,
contentTextStyle: textTheme.bodyMedium?.copyWith(
color: scheme.onInverseSurface,
),
actionTextColor: scheme.inversePrimary,
closeIconColor: scheme.onInverseSurface,
elevation: 6,
insetPadding: const EdgeInsets.fromLTRB(
Grid.gutter,
Grid.xxs,
Grid.gutter,
Grid.xs,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(Radii.md),
borderRadius: BorderRadius.circular(Radii.lg),
),
),
);

View File

@@ -0,0 +1,29 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
/// The outcome communicated by a notice, independent of its wording.
enum ToastKind { generic, success, error }
/// Plays outcome-specific feedback without blocking the notice.
Future<void> toastHaptic(ToastKind kind) async {
try {
if (kind != ToastKind.generic &&
!kIsWeb &&
defaultTargetPlatform == TargetPlatform.iOS) {
await const MethodChannel('buzz/haptics').invokeMethod<void>(kind.name);
return;
}
switch (kind) {
case ToastKind.generic:
await HapticFeedback.lightImpact();
case ToastKind.success:
await HapticFeedback.mediumImpact();
case ToastKind.error:
await HapticFeedback.heavyImpact();
}
} on PlatformException {
// Haptics are optional; feedback must still be displayed.
} on MissingPluginException {
// Some platforms and test embedders do not provide haptics.
}
}

View File

@@ -0,0 +1,300 @@
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '../theme/theme.dart';
import '../toast_haptic.dart';
import 'toast_capsule_content.dart';
export '../toast_haptic.dart' show ToastKind;
part 'buzz_toast_island.dart';
part 'reconnect_capsule.dart';
final _toastCoordinators = Expando<_ToastCoordinator>();
_ToastCoordinator _toastCoordinator(BuildContext context) {
final overlay = Overlay.of(context, rootOverlay: true);
return _toastCoordinators[overlay] ??= _ToastCoordinator();
}
class _ToastCoordinator extends ValueNotifier<bool> {
_ToastCoordinator() : super(false);
_ToastHandle? active;
}
/// Shows brief feedback above routes and modal sheets.
/// A new notice replaces the current one instead of building a stale queue.
/// Supported portrait iPhones morph from the Dynamic Island automatically.
void showBuzzToast(
BuildContext context,
String message, {
ToastKind kind = ToastKind.generic,
VoidCallback? onRetry,
Rect? islandOrigin,
double islandSpeed = 0.75,
}) {
final overlay = Overlay.of(context, rootOverlay: true);
final coordinator = _toastCoordinator(context);
coordinator.active?.remove();
late final _ToastHandle handle;
final entry = OverlayEntry(
builder: (_) => _ToastBubble(
message: message,
islandOrigin: islandOrigin,
islandSpeed: islandSpeed,
onDismiss: handle.remove,
onRetry: onRetry == null
? null
: () {
handle.remove();
if (context.mounted) onRetry();
},
),
);
handle = _ToastHandle(entry, () {
if (identical(coordinator.active, handle)) {
coordinator.active = null;
coordinator.value = false;
}
});
coordinator.active = handle;
coordinator.value = true;
overlay.insert(entry);
unawaited(toastHaptic(kind));
}
class _ToastHandle {
_ToastHandle(this.entry, this.onRemove);
final OverlayEntry entry;
final VoidCallback onRemove;
bool removed = false;
void remove() {
if (removed) return;
removed = true;
entry.remove();
entry.dispose();
onRemove();
}
}
class _ToastBubble extends HookWidget {
const _ToastBubble({
required this.message,
required this.onDismiss,
this.onRetry,
this.islandOrigin,
this.islandSpeed = 0.75,
this.visible = true,
this.persistent = false,
this.actionLabel = 'Retry',
});
final String message;
final VoidCallback? onRetry;
final VoidCallback onDismiss;
final Rect? islandOrigin;
final double islandSpeed;
final bool visible;
final bool persistent;
final String actionLabel;
@override
Widget build(BuildContext context) {
final origin = islandOrigin ?? _toastIslandOrigin(context);
final reduceMotion = MediaQuery.disableAnimationsOf(context);
final accessible = MediaQuery.accessibleNavigationOf(context);
final program = useFuture(
useMemoized(
() => origin != null && !reduceMotion ? _loadIslandProgram() : null,
[origin != null, reduceMotion],
),
);
final shader = useMemoized(() => program.data?.fragmentShader(), [
program.data,
]);
useEffect(
() =>
() => shader?.dispose(),
[shader],
);
final waitingForIsland =
origin != null &&
!reduceMotion &&
program.connectionState != ConnectionState.done;
final island = reduceMotion || shader == null ? null : origin;
final speed = island == null ? 1.0 : islandSpeed.clamp(1 / 3, 1.0);
final entranceMs = (280 / speed).round();
final controller = useAnimationController(
duration: Duration(milliseconds: entranceMs),
reverseDuration: Duration(milliseconds: (240 / speed).round()),
);
useEffect(
() {
if (waitingForIsland) return null;
if (persistent) {
if (reduceMotion) {
controller.value = visible ? 1 : 0;
} else if (visible) {
controller.forward();
} else {
controller.reverse();
}
return null;
}
if (reduceMotion) {
controller.value = 1;
} else {
controller.forward();
}
final timer = accessible && onRetry != null
? null
: Timer(
Duration(
milliseconds:
(accessible || onRetry != null ? 6000 : 3000) +
(reduceMotion ? 0 : entranceMs),
),
() async {
if (!reduceMotion) {
try {
await controller.reverse().orCancel;
} on TickerCanceled {
return;
}
}
onDismiss();
},
);
return () => timer?.cancel();
},
[
controller,
reduceMotion,
accessible,
persistent,
visible,
waitingForIsland,
],
);
final value = useAnimation(controller);
if (waitingForIsland || (persistent && value == 0)) {
return const SizedBox.shrink();
}
final exiting = controller.status == AnimationStatus.reverse;
// The exit collapses immediately while upward travel accelerates later.
// Reversing the entry width curve leaves the text fully exposed too long.
final progress = exiting
? Curves.easeOutQuad.transform(value)
: const Cubic(0.2, 1.1, 0.4, 1).transform(value);
final reveal = exiting
? Curves.easeInCubic.transform(value)
: Curves.easeOutCubic.transform(value);
final contentOpacity = exiting
? value * value
: island == null
? 1.0
: const Interval(0.25, 0.8).transform(value);
final top = MediaQuery.viewPaddingOf(context).top + Grid.xxs;
// Follow the system preference even when the current route overrides Theme.
final dark = MediaQuery.platformBrightnessOf(context) == Brightness.dark;
final background = island != null
? Colors.black
: dark
? darkColorScheme.surfaceContainer
: lightColorScheme.inverseSurface;
final foreground = dark
? darkColorScheme.onSurface
: lightColorScheme.onInverseSurface;
return Positioned(
top: top,
left: Grid.gutter,
right: Grid.gutter,
child: IgnorePointer(
ignoring: onRetry == null || exiting,
child: Align(
alignment: Alignment.topCenter,
child: FractionalTranslation(
translation: Offset(
0,
-(island == null ? 1 : 0.5) * (1 - progress),
),
child: Transform.translate(
offset: Offset(
0,
((island?.center.dy ?? 0) - top) * (1 - progress),
),
child: Semantics(
liveRegion: true,
onDismiss: persistent ? null : onDismiss,
// Lay text out once at its full width. Only the capsule's
// painted bounds expand, revealing rather than scaling text.
child: CustomPaint(
painter: island == null || shader == null
? null
: _ToastIslandSurface(
shader: shader,
reveal: reveal,
pixelRatio: MediaQuery.devicePixelRatioOf(context),
island: island,
top: top,
progress: progress,
),
child: PhysicalShape(
clipper: _ToastRevealClipper(reveal),
clipBehavior: Clip.antiAlias,
color: island != null && shader != null
? Colors.transparent
: background,
elevation: island != null && shader != null ? 0 : 4,
shadowColor: Colors.black.withValues(alpha: 0.18),
child: Opacity(
opacity: contentOpacity,
child: ToastCapsuleContent(
message: message,
foreground: foreground,
actionLabel: actionLabel,
onAction: onRetry,
),
),
),
),
),
),
),
),
),
);
}
}
class _ToastRevealClipper extends CustomClipper<Path> {
const _ToastRevealClipper(this.progress);
final double progress;
@override
Path getClip(Size size) {
final collapsedWidth = size.height.clamp(0.0, size.width);
final width = collapsedWidth + (size.width - collapsedWidth) * progress;
return RoundedSuperellipseBorder(
borderRadius: BorderRadius.circular(size.height / 2),
).getOuterPath(
Rect.fromCenter(
center: size.center(Offset.zero),
width: width,
height: size.height,
),
);
}
@override
bool shouldReclip(_ToastRevealClipper oldClipper) =>
oldClipper.progress != progress;
}

View File

@@ -0,0 +1,103 @@
part of 'buzz_toast.dart';
// Portrait Dynamic Island iPhones expose a top safe area above 50 points.
// Read the live inset so an early cold-start window cannot hide the effect.
Rect? _toastIslandOrigin(BuildContext context) {
final media = MediaQuery.of(context);
if (defaultTargetPlatform != TargetPlatform.iOS ||
media.orientation != Orientation.portrait ||
media.size.shortestSide >= 600 ||
media.viewPadding.top <= 50) {
return null;
}
return Rect.fromLTWH(
(media.size.width - 120) / 2,
11 + (media.viewPadding.top - 59).clamp(0.0, double.infinity),
120,
36,
);
}
Future<ui.FragmentProgram?>? _islandProgram;
Future<ui.FragmentProgram?> _loadIslandProgram() =>
_islandProgram ??= () async {
try {
return await ui.FragmentProgram.fromAsset('shaders/toast_island.frag');
} catch (error) {
debugPrint('Could not load toast island effect: $error');
return null;
}
}();
// Paint the island and moving capsule together. Text/actions are a separate,
// sharp layer, with no shadow or opaque capsule dividing the merged surface.
class _ToastIslandSurface extends CustomPainter {
const _ToastIslandSurface({
required this.shader,
required this.island,
required this.top,
required this.progress,
required this.reveal,
required this.pixelRatio,
});
final ui.FragmentShader shader;
final Rect island;
final double top;
final double progress;
final double reveal;
final double pixelRatio;
@override
void paint(Canvas canvas, Size size) {
final bubbleTop =
top + (island.center.dy - top - size.height / 2) * (1 - progress);
final localIsland = Rect.fromCenter(
center: Offset(size.width / 2, island.center.dy - bubbleTop),
width: island.width,
height: island.height,
);
final t = reveal.clamp(0.0, 1.0);
final travel = progress.clamp(0.0, 1.0);
final toast = Rect.fromCenter(
center: size.center(Offset.zero),
// Start compact even when the message is narrower than the island.
// The stationary island keeps its own full-width outline above.
width: island.height.clamp(0.0, size.width) * (1 - t) + size.width * t,
height: island.height * (1 - t) + size.height * t,
);
final bounds = localIsland.expandToInclude(toast).inflate(24);
final origin = bounds.topLeft;
final values = [
localIsland.center.dx - origin.dx,
localIsland.center.dy - origin.dy,
localIsland.width / 2,
localIsland.height / 2,
toast.center.dx - origin.dx,
toast.center.dy - origin.dy,
toast.width / 2,
toast.height / 2,
// Follow travel, not width: the outro narrows early but must keep
// merging until it actually reaches the island. Endpoints stay flat.
128 * travel * (1 - travel),
0.75 / pixelRatio,
];
for (var i = 0; i < values.length; i++) {
shader.setFloat(i, values[i]);
}
canvas.save();
canvas.translate(origin.dx, origin.dy);
canvas.drawRect(Offset.zero & bounds.size, Paint()..shader = shader);
canvas.restore();
}
@override
bool shouldRepaint(_ToastIslandSurface oldDelegate) =>
shader != oldDelegate.shader ||
island != oldDelegate.island ||
top != oldDelegate.top ||
progress != oldDelegate.progress ||
reveal != oldDelegate.reveal ||
pixelRatio != oldDelegate.pixelRatio;
}

View File

@@ -0,0 +1,18 @@
import 'dart:async';
import 'package:flutter/material.dart';
import '../toast_haptic.dart';
export '../toast_haptic.dart' show ToastKind;
/// Applies the shared feedback pulse to the remaining actionable snackbars.
extension FeedbackSnackBar on ScaffoldMessengerState {
/// Shows the original snackbar, preserving its actions, queue, and lifetime.
ScaffoldFeatureController<SnackBar, SnackBarClosedReason>
showFeedbackSnackBar(SnackBar snackBar, {required ToastKind kind}) {
final controller = showSnackBar(snackBar);
unawaited(toastHaptic(kind));
return controller;
}
}

View File

@@ -0,0 +1,35 @@
part of 'buzz_toast.dart';
/// Parent-owned persistent feedback with the same motion as transient toasts.
class ReconnectCapsule extends HookWidget {
const ReconnectCapsule({
super.key,
required this.onSignIn,
this.visible = true,
this.islandOrigin,
this.islandSpeed = 0.75,
});
final VoidCallback onSignIn;
final bool visible;
final Rect? islandOrigin;
final double islandSpeed;
@override
Widget build(BuildContext context) {
final transientVisible = useValueListenable(_toastCoordinator(context));
// Remove immediately so neither text nor island surfaces overlap.
// Remounting after dismissal restarts the persistent entrance if needed.
if (transientVisible) return const SizedBox.shrink();
return _ToastBubble(
message: 'Reconnect to Builderlab',
actionLabel: 'Sign in',
onRetry: onSignIn,
onDismiss: () {},
persistent: true,
visible: visible,
islandOrigin: islandOrigin,
islandSpeed: islandSpeed,
);
}
}

View File

@@ -1,3 +1,4 @@
import 'package:buzz/shared/widgets/feedback_snackbar.dart';
import 'dart:async';
import 'package:flutter/foundation.dart';
@@ -68,8 +69,9 @@ Future<void> showTextEditor({
}
void _showSaveError(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("We couldn't save this change. Try again.")),
ScaffoldMessenger.of(context).showFeedbackSnackBar(
const SnackBar(content: Text('Couldn’t save changes')),
kind: ToastKind.error,
);
}
@@ -111,7 +113,7 @@ class _TextEditSheet extends HookWidget {
Navigator.of(context).pop();
return;
}
error.value = "We couldn't save this change. Try again.";
error.value = 'Couldn’t save changes';
} finally {
if (context.mounted) isSaving.value = false;
}

View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import '../theme/theme.dart';
/// Shared text and inset action pill for temporary and persistent feedback.
class ToastCapsuleContent extends StatelessWidget {
const ToastCapsuleContent({
super.key,
required this.message,
required this.foreground,
this.actionLabel = 'Retry',
this.onAction,
});
final String message;
final Color foreground;
final String actionLabel;
final VoidCallback? onAction;
@override
Widget build(BuildContext context) {
final text = Padding(
padding: const EdgeInsets.symmetric(
horizontal: Grid.gutter,
vertical: Grid.twelve,
),
child: Text(
message,
textAlign: TextAlign.center,
style: context.textTheme.bodyMedium?.copyWith(
color: foreground,
fontWeight: FontWeight.w600,
),
),
);
if (onAction == null) return text;
return IntrinsicWidth(
child: IntrinsicHeight(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(child: Center(widthFactor: 1, child: text)),
Padding(
padding: const EdgeInsets.only(top: 6, right: 6, bottom: 6),
child: FilledButton(
onPressed: onAction,
style: FilledButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
shape: const RoundedSuperellipseBorder(
borderRadius: BorderRadius.all(Radius.circular(999)),
),
minimumSize: const Size(48, 36),
padding: const EdgeInsets.symmetric(horizontal: Grid.gutter),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: Text(actionLabel),
),
),
],
),
),
);
}
}