Skip to content

Commit

Permalink
Fixed issue with BoxScrollViews in Hero animations
Browse files Browse the repository at this point in the history
  • Loading branch information
youssef-attia committed Jun 8, 2022
1 parent 889a15e commit 67adf0f
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions packages/flutter/lib/src/widgets/heroes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'basic.dart';
import 'binding.dart';
Expand Down Expand Up @@ -137,7 +138,10 @@ enum HeroFlightDirection {
/// is, by default, used to do the transition: when going from route A to route
/// B, route B's hero's widget is placed over route A's hero's widget. If a
/// [flightShuttleBuilder] is supplied, its output widget is shown during the
/// flight transition instead.
/// flight transition instead. If overriding [flightShuttleBuilder] leads to
/// gaps or jumps arising in the animation, try interpolating between
/// [MediaQueryData] padding values of the different contexts in the shuttle
/// builder.
///
/// By default, both route A and route B's heroes are hidden while the
/// transitioning widget is animating in-flight above the 2 routes.
Expand Down Expand Up @@ -910,8 +914,8 @@ class HeroController extends NavigatorObserver {
final NavigatorState? navigator = this.navigator;
final OverlayState? overlay = navigator?.overlay;
// If the navigator or the overlay was removed before this end-of-frame
// callback was called, then don't actually start a transition, and we don'
// t have to worry about any Hero widget we might have hidden in a previous
// callback was called, then don't actually start a transition, and we don't
// have to worry about any Hero widget we might have hidden in a previous
// flight, or ongoing flights.
if (navigator == null || overlay == null) {
return;
Expand Down Expand Up @@ -998,7 +1002,32 @@ class HeroController extends NavigatorObserver {
BuildContext toHeroContext,
) {
final Hero toHero = toHeroContext.widget as Hero;
return toHero.child;
if (MediaQuery.maybeOf(toHeroContext) == null && MediaQuery.maybeOf(fromHeroContext) == null) {
return toHero.child;
}
final MediaQueryData chosenMediaQueryData = MediaQuery.maybeOf(toHeroContext) ?? MediaQuery.of(fromHeroContext);

final EdgeInsets fromHeroPadding = MediaQuery.maybeOf(fromHeroContext)?.padding?? EdgeInsets.zero;
final EdgeInsets toHeroPadding = MediaQuery.maybeOf(toHeroContext)?.padding?? EdgeInsets.zero;


return AnimatedBuilder(
animation: animation,
builder: (BuildContext context, Widget? child) {
return MediaQuery(
data: chosenMediaQueryData.copyWith(
padding: (flightDirection == HeroFlightDirection.push)
? Tween<EdgeInsets>(
begin: fromHeroPadding,
end: toHeroPadding,
).evaluate(animation)
: Tween<EdgeInsets>(
begin: toHeroPadding,
end: fromHeroPadding,
).evaluate(animation),
),
child: toHero.child);
});
}
}

Expand Down

0 comments on commit 67adf0f

Please sign in to comment.