6e8c9b1a9e
The just-sent (or queued) message slides up 20px, fades and grows from 0.96 over 280ms on an emphasized decelerate curve. Only a send marks it: history, scroll restore, other devices, replies and the server copy replacing the local one appear in place. Row keys follow the operation id so the server copy keeps the row. Reduced motion shows it at once. The capture fixture now accepts chat_prompt.
250 lines
7.8 KiB
Dart
250 lines
7.8 KiB
Dart
import 'package:flutter/widgets.dart';
|
|
|
|
/// Short, quiet motion shared by the app: opening and closing sections,
|
|
/// counts and statuses changing, live items arriving. Every duration drops
|
|
/// to zero when the system asks for reduced motion.
|
|
abstract final class Motion {
|
|
/// A count, an icon or a status swapping in place.
|
|
static const Duration quick = Duration(milliseconds: 150);
|
|
|
|
/// A section opening or closing, a bar changing its actions.
|
|
static const Duration standard = Duration(milliseconds: 200);
|
|
|
|
/// The total duration of a tab's Material fade-through transition.
|
|
static const Duration tabFadeThrough = Duration(milliseconds: 250);
|
|
|
|
/// The scale at the midpoint of a tab's fade-through transition.
|
|
static const double tabFadeThroughScale = 0.96;
|
|
|
|
/// The point at which the incoming tab begins to appear.
|
|
static const double tabFadeThroughIncomingAt = 0.35;
|
|
|
|
// The entrance pop below is shared by the floating tab buttons and every
|
|
// piece of the top bar (Back, the title, the actions pill and each action
|
|
// in it); see `PopEntrance`.
|
|
|
|
/// Duration of each item's entrance pop.
|
|
static const Duration tabEntranceDuration = Duration(milliseconds: 260);
|
|
|
|
/// Delay between neighbouring items entering as one group (tabs, or the
|
|
/// top bar's pieces from the leading edge).
|
|
static const Duration tabEntranceStagger = Duration(milliseconds: 70);
|
|
|
|
/// The scale at which an item starts its entrance pop.
|
|
static const double tabEntranceScaleBegin = 0.6;
|
|
|
|
/// The upward travel distance of an item's entrance pop, in logical
|
|
/// pixels.
|
|
static const double tabEntranceSlideDistance = 6;
|
|
|
|
/// The fraction of an item's entrance spent fading in.
|
|
static const double tabEntranceOpacityPortion = 0.6;
|
|
|
|
/// The gentle overshoot of an item's entrance pop.
|
|
static const Curve tabEntranceCurve = Curves.easeOutBack;
|
|
|
|
/// How long a tab button's selection tint takes to cross-fade.
|
|
static const Duration tabSelectDuration = Duration(milliseconds: 220);
|
|
|
|
/// The newly selected tab icon's brief bounce.
|
|
static const Duration tabBounceDuration = Duration(milliseconds: 180);
|
|
|
|
/// The icon's scale at the top of its bounce.
|
|
static const double tabBounceScale = 1.08;
|
|
|
|
/// How much larger the selected tab's button (and its icon) is than the
|
|
/// others; it grows and shrinks with the selection tint, and its
|
|
/// neighbours keep their gaps to it.
|
|
static const double tabSelectedScale = 1.2;
|
|
|
|
/// How long a pressed top-bar control takes to sink.
|
|
static const Duration barPressDuration = Duration(milliseconds: 90);
|
|
|
|
/// The scale of a top-bar control while it is held down.
|
|
static const double barPressScale = 0.94;
|
|
|
|
/// The opacity of the pressed tint over a top-bar control.
|
|
static const double barPressTintOpacity = 0.14;
|
|
|
|
/// The spring a released top-bar control returns on: quick, with a
|
|
/// barely visible overshoot.
|
|
static const SpringDescription barReleaseSpring = SpringDescription(
|
|
mass: 1,
|
|
stiffness: 520,
|
|
damping: 28,
|
|
);
|
|
|
|
/// How long a message the operator just sent takes to rise into the
|
|
/// conversation from the composer.
|
|
static const Duration sentMessageDuration = Duration(milliseconds: 280);
|
|
|
|
/// How far below its resting place a just-sent message starts, in logical
|
|
/// pixels.
|
|
static const double sentMessageRise = 20;
|
|
|
|
/// The scale a just-sent message grows from.
|
|
static const double sentMessageScaleBegin = 0.96;
|
|
|
|
/// The fraction of a just-sent message's entrance spent fading in.
|
|
static const double sentMessageOpacityPortion = 0.6;
|
|
|
|
/// Material's emphasized decelerate: quick off the composer, settling
|
|
/// softly with no overshoot.
|
|
static const Curve sentMessageCurve = Cubic(0.05, 0.7, 0.1, 1);
|
|
|
|
static const Curve curve = Curves.easeOutCubic;
|
|
|
|
/// [duration], or zero under the system's reduce-motion setting.
|
|
static Duration of(BuildContext context, Duration duration) =>
|
|
MediaQuery.maybeDisableAnimationsOf(context) ?? false
|
|
? Duration.zero
|
|
: duration;
|
|
}
|
|
|
|
/// Swaps [child] with a short cross-fade whenever its key changes.
|
|
class MotionSwitcher extends StatelessWidget {
|
|
const MotionSwitcher({
|
|
super.key,
|
|
required this.child,
|
|
this.duration = Motion.quick,
|
|
this.scale = false,
|
|
});
|
|
|
|
final Widget child;
|
|
final Duration duration;
|
|
|
|
/// Also grows the incoming child from 80%: for badges and pills.
|
|
final bool scale;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => AnimatedSwitcher(
|
|
duration: Motion.of(context, duration),
|
|
switchInCurve: Motion.curve,
|
|
switchOutCurve: Motion.curve,
|
|
transitionBuilder: (child, animation) {
|
|
final faded = FadeTransition(opacity: animation, child: child);
|
|
if (!scale) return faded;
|
|
return ScaleTransition(
|
|
scale: Tween<double>(begin: 0.8, end: 1).animate(animation),
|
|
child: faded,
|
|
);
|
|
},
|
|
child: child,
|
|
);
|
|
}
|
|
|
|
/// Names the items of a live list, so items that arrive after the first load
|
|
/// can enter with a short fade and slide while the first load and items
|
|
/// scrolled into view appear at once.
|
|
class ArrivalScope extends StatefulWidget {
|
|
const ArrivalScope({super.key, required this.ids, required this.child});
|
|
|
|
/// Every item currently in the list, built or not.
|
|
final Iterable<Object> ids;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<ArrivalScope> createState() => _ArrivalScopeState();
|
|
}
|
|
|
|
class _ArrivalScopeState extends State<ArrivalScope> {
|
|
final Set<Object> _known = {};
|
|
final Set<Object> _fresh = {};
|
|
bool _primed = false;
|
|
|
|
void _absorb() {
|
|
final ids = widget.ids.toList();
|
|
if (!_primed) {
|
|
// The first non-empty list is the starting point, not an arrival.
|
|
if (ids.isEmpty) return;
|
|
_known.addAll(ids);
|
|
_primed = true;
|
|
return;
|
|
}
|
|
for (final id in ids) {
|
|
if (_known.add(id)) _fresh.add(id);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_absorb();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(ArrivalScope oldWidget) {
|
|
super.didUpdateWidget(oldWidget);
|
|
_absorb();
|
|
}
|
|
|
|
/// True once for an item that arrived after the first load.
|
|
bool _claim(Object id) => _fresh.remove(id);
|
|
|
|
@override
|
|
Widget build(BuildContext context) =>
|
|
_ArrivalData(state: this, child: widget.child);
|
|
}
|
|
|
|
class _ArrivalData extends InheritedWidget {
|
|
const _ArrivalData({required this.state, required super.child});
|
|
|
|
final _ArrivalScopeState state;
|
|
|
|
@override
|
|
bool updateShouldNotify(_ArrivalData oldWidget) => false;
|
|
}
|
|
|
|
/// One item of an [ArrivalScope]: fades and slides in when it is new.
|
|
class Arrival extends StatefulWidget {
|
|
const Arrival({super.key, required this.id, required this.child});
|
|
|
|
final Object id;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<Arrival> createState() => _ArrivalState();
|
|
}
|
|
|
|
class _ArrivalState extends State<Arrival> with SingleTickerProviderStateMixin {
|
|
AnimationController? _controller;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
if (_controller != null) return;
|
|
final scope = context.getInheritedWidgetOfExactType<_ArrivalData>()?.state;
|
|
final duration = Motion.of(context, Motion.standard);
|
|
if (scope == null ||
|
|
duration == Duration.zero ||
|
|
!scope._claim(widget.id)) {
|
|
return;
|
|
}
|
|
_controller = AnimationController(vsync: this, duration: duration)
|
|
..forward();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller?.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final controller = _controller;
|
|
if (controller == null) return widget.child;
|
|
final curved = CurvedAnimation(parent: controller, curve: Motion.curve);
|
|
return FadeTransition(
|
|
opacity: curved,
|
|
child: SlideTransition(
|
|
position: Tween<Offset>(
|
|
begin: const Offset(0, 0.15),
|
|
end: Offset.zero,
|
|
).animate(curved),
|
|
child: widget.child,
|
|
),
|
|
);
|
|
}
|
|
}
|