feat(app): short motion for collapsibles, badges, new runs and the action bar; none under reduced motion

This commit is contained in:
2026-10-23 22:05:30 +01:00
parent c467872ee3
commit ae43182a2b
9 changed files with 313 additions and 44 deletions
+16 -4
View File
@@ -1,3 +1,4 @@
import '../ui/motion/motion.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@@ -145,9 +146,12 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
automaticallyImplyLeading: false,
middle: Text(spec?.title ?? details.label),
trailing: spec != null && spec.actions.isNotEmpty
? Row(
mainAxisSize: MainAxisSize.min,
children: spec.actions,
? MotionSwitcher(
child: Row(
key: ObjectKey(_bar.ownerFor(_selected)),
mainAxisSize: MainAxisSize.min,
children: spec.actions,
),
)
: widget.onSearch == null
? null
@@ -209,7 +213,15 @@ class _AdaptiveShellState extends State<AdaptiveShell> {
),
title: Text(spec?.title ?? details.label),
actions: [
...?spec?.actions,
if (spec != null && spec.actions.isNotEmpty)
// A screen taking the bar over cross-fades its actions in.
MotionSwitcher(
child: Row(
key: ObjectKey(_bar.ownerFor(_selected)),
mainAxisSize: MainAxisSize.min,
children: spec.actions,
),
),
if (widget.onSearch != null && (spec?.actions.isEmpty ?? true))
IconButton(
key: const ValueKey('shell.search'),
+46 -27
View File
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../features/attention/domain/attention_models.dart';
import '../ui/motion/motion.dart';
/// Mirrors the Runs-heading bell count onto the Runs destination icon.
///
@@ -28,7 +29,16 @@ class AttentionDestinationIcon extends StatelessWidget {
final visible = count > 0;
final Widget icon = cupertino
? _CupertinoCountOverlay(count: count, visible: visible, child: child)
: Badge(label: Text('$count'), isLabelVisible: visible, child: child);
: Badge(
label: visible
? MotionSwitcher(
scale: true,
child: Text('$count', key: ValueKey(count)),
)
: null,
isLabelVisible: visible,
child: child,
);
if (!visible) return icon;
// The number alone would read as a stray "3"; the item carries the bell's
// full label instead.
@@ -72,7 +82,10 @@ class _CupertinoCountOverlay extends StatelessWidget {
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: Text('$count', style: style),
child: MotionSwitcher(
scale: true,
child: Text('$count', key: ValueKey(count), style: style),
),
),
),
),
@@ -101,36 +114,37 @@ class ActivityBadge extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (count <= 0) return child;
final visible = count > 0;
final color = cupertino
? CupertinoColors.systemBlue.resolveFrom(context)
: Theme.of(context).colorScheme.primary;
final text = cupertino
? CupertinoColors.white
: Theme.of(context).colorScheme.onPrimary;
return Semantics(
label: '$count $label',
child: ExcludeSemantics(
child: Stack(
clipBehavior: Clip.none,
children: [
child,
PositionedDirectional(
top: bottom ? null : -6,
bottom: bottom ? -6 : null,
end: -10,
child: DecoratedBox(
decoration: ShapeDecoration(
color: color,
shape: const StadiumBorder(),
),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 1,
),
final stack = Stack(
clipBehavior: Clip.none,
children: [
child,
PositionedDirectional(
top: bottom ? null : -6,
bottom: bottom ? -6 : null,
end: -10,
child: AnimatedScale(
scale: visible ? 1 : 0,
duration: Motion.of(context, Motion.quick),
curve: Motion.curve,
child: DecoratedBox(
decoration: ShapeDecoration(
color: color,
shape: const StadiumBorder(),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1),
child: MotionSwitcher(
scale: true,
child: Text(
'$count',
visible ? '$count' : '',
key: ValueKey(count),
style: TextStyle(
color: text,
fontSize: 10,
@@ -140,9 +154,14 @@ class ActivityBadge extends StatelessWidget {
),
),
),
],
),
),
),
],
);
if (!visible) return stack;
return Semantics(
label: '$count $label',
child: ExcludeSemantics(child: stack),
);
}
}
+4
View File
@@ -37,6 +37,10 @@ class ShellBarRegistry extends ChangeNotifier {
ShellBarSpec? specFor(AppDestination destination) => _specs[destination]?.$2;
/// The screen that published [destination]'s bar; it changes when another
/// screen takes the bar over.
Object? ownerFor(AppDestination destination) => _specs[destination]?.$1;
void _set(AppDestination destination, Object owner, ShellBarSpec spec) {
// A screen's update can land after the shell itself has gone.
if (_disposed) return;