Skip to content

Commit bfce02c

Browse files
committed
Ability to customize the curve used in the hero animation
flutter#26150
1 parent 1f79ec0 commit bfce02c

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎packages/flutter/lib/src/widgets/heroes.dart‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class Hero extends StatefulWidget {
273273

274274
/// The curve to use in the reverse direction.
275275
///
276-
/// If this property is null, the default, then curve.flipped is used.
276+
/// If this property is null, the flipped version of [curve] is used.
277277
final Curve? reverseCurve;
278278

279279
// Returns a map of all of the heroes in `context` indexed by hero tag that
@@ -472,13 +472,21 @@ class _HeroFlightManifest {
472472
CurvedAnimation? _animation;
473473

474474
Animation<double> get animation {
475-
final Curve reverseCurve = (type == HeroFlightDirection.push) ?
476-
(toHero.widget.reverseCurve ?? toHero.widget.curve.flipped)
477-
: (fromHero.widget.reverseCurve ?? fromHero.widget.curve.flipped);
475+
final Curve curve, reverseCurve;
476+
final Animation<double> parent;
477+
if (type == HeroFlightDirection.push) {
478+
parent = toRoute.animation!;
479+
curve = toHero.widget.curve;
480+
reverseCurve = toHero.widget.reverseCurve ?? toHero.widget.curve.flipped;
481+
} else {
482+
parent = fromRoute.animation!;
483+
curve = fromHero.widget.curve;
484+
reverseCurve = fromHero.widget.reverseCurve ?? fromHero.widget.curve.flipped;
485+
}
478486

479487
return _animation ??= CurvedAnimation(
480-
parent: (type == HeroFlightDirection.push) ? toRoute.animation! : fromRoute.animation!,
481-
curve: (type == HeroFlightDirection.push) ? toHero.widget.curve : fromHero.widget.curve,
488+
parent: parent,
489+
curve: curve,
482490
reverseCurve: isDiverted ? null : reverseCurve,
483491
);
484492
}

0 commit comments

Comments
 (0)