9551eceaed
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
149 lines
4.3 KiB
Dart
149 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'container_transform_flight.dart';
|
|
import 'container_transform_gestures.dart';
|
|
import 'container_transform_source.dart';
|
|
import 'motion.dart';
|
|
|
|
/// How long a page released mid-swipe takes to settle, as in iOS.
|
|
const Duration _droppedSwipeDuration = Duration(milliseconds: 350);
|
|
|
|
/// A full-screen page that grows out of the item that opened it and shrinks
|
|
/// back into it on Back (Material's container transform).
|
|
///
|
|
/// [link] resolves the item each time the page animates, so closing after
|
|
/// another item took the page shrinks into that one. When the item is not on
|
|
/// screen, or the system asks for reduced motion, the page fades instead.
|
|
/// The list behind stays put. Android's predictive back drives the shrink
|
|
/// with the finger. The animation-speed setting scales every duration
|
|
/// through the scheduler clock.
|
|
class ContainerTransformPageRoute<T> extends PageRoute<T>
|
|
implements ContainerTransformGestureRoute {
|
|
ContainerTransformPageRoute({
|
|
required this.builder,
|
|
required this.link,
|
|
super.settings,
|
|
});
|
|
|
|
final WidgetBuilder builder;
|
|
final ContainerTransformLink link;
|
|
|
|
bool get _reducedMotion {
|
|
final context = navigator?.context;
|
|
return context != null &&
|
|
(MediaQuery.maybeDisableAnimationsOf(context) ?? false);
|
|
}
|
|
|
|
@override
|
|
Duration get transitionDuration =>
|
|
_reducedMotion ? Motion.quick : Motion.containerTransform;
|
|
|
|
@override
|
|
Duration get reverseTransitionDuration =>
|
|
_reducedMotion ? Motion.quick : Motion.containerTransformReverse;
|
|
|
|
@override
|
|
bool get opaque => true;
|
|
|
|
@override
|
|
bool get maintainState => true;
|
|
|
|
@override
|
|
Color? get barrierColor => null;
|
|
|
|
@override
|
|
String? get barrierLabel => null;
|
|
|
|
/// The list this page grew from never moves under it.
|
|
@override
|
|
bool canTransitionFrom(TransitionRoute<dynamic> previousRoute) => false;
|
|
|
|
@override
|
|
Widget buildPage(
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
) => Semantics(
|
|
scopesRoute: true,
|
|
explicitChildNodes: true,
|
|
child: builder(context),
|
|
);
|
|
|
|
@override
|
|
Widget buildTransitions(
|
|
BuildContext context,
|
|
Animation<double> animation,
|
|
Animation<double> secondaryAnimation,
|
|
Widget child,
|
|
) {
|
|
final reduced = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
|
final page = ContainerTransformFlight(
|
|
animation: animation,
|
|
origin: reduced ? null : link.resolve,
|
|
closing: () =>
|
|
animation.status == AnimationStatus.reverse || popGestureInProgress,
|
|
tracking: () => popGestureInProgress,
|
|
pageColor: Theme.of(context).scaffoldBackgroundColor,
|
|
scrimColor: Theme.of(context).colorScheme.scrim,
|
|
child: child,
|
|
);
|
|
return ContainerTransformBackGestures(route: this, child: page);
|
|
}
|
|
|
|
@override
|
|
bool get backGestureEnabled =>
|
|
isCurrent &&
|
|
popGestureEnabled &&
|
|
!(navigator?.userGestureInProgress ?? true);
|
|
|
|
@override
|
|
void startSwipeBack() => navigator?.didStartUserGesture();
|
|
|
|
@override
|
|
void updateSwipeBack(double fraction) {
|
|
if (!isCurrent) return;
|
|
controller?.value -= fraction;
|
|
}
|
|
|
|
@override
|
|
void endSwipeBack(double velocity) {
|
|
final controller = this.controller;
|
|
final navigator = this.navigator;
|
|
if (controller == null || navigator == null) return;
|
|
// As in iOS: a fling decides; otherwise the page goes back past halfway.
|
|
final bool stay;
|
|
if (!isCurrent) {
|
|
stay = isActive;
|
|
} else if (velocity.abs() >= 1) {
|
|
stay = velocity <= 0;
|
|
} else {
|
|
stay = controller.value > 0.5;
|
|
}
|
|
const curve = Curves.fastEaseInToSlowEaseOut;
|
|
if (stay) {
|
|
controller.animateTo(1, duration: _droppedSwipeDuration, curve: curve);
|
|
} else {
|
|
if (isCurrent) navigator.pop();
|
|
if (controller.isAnimating) {
|
|
controller.animateBack(
|
|
0,
|
|
duration: _droppedSwipeDuration,
|
|
curve: curve,
|
|
);
|
|
}
|
|
}
|
|
if (!controller.isAnimating) {
|
|
navigator.didStopUserGesture();
|
|
return;
|
|
}
|
|
// The gesture lasts until the page settles, so the shrink keeps
|
|
// following linearly instead of jumping onto the eased curve.
|
|
late final AnimationStatusListener settle;
|
|
settle = (_) {
|
|
navigator.didStopUserGesture();
|
|
controller.removeStatusListener(settle);
|
|
};
|
|
controller.addStatusListener(settle);
|
|
}
|
|
}
|