Skip to content

Commit 31aa3a9

Browse files
committed
fix: should not flicker
1 parent c1b0772 commit 31aa3a9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/src/rendering/local_hero_layer.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/animation.dart';
22
import 'package:flutter/rendering.dart';
3+
import 'package:flutter/scheduler.dart';
34
import 'package:local_hero/src/rendering/controller.dart';
45
import 'package:local_hero/src/rendering/layer.dart';
56

@@ -144,6 +145,16 @@ class RenderLocalHeroFollowerLayer extends RenderProxyBox {
144145
: constraints.enforce(BoxConstraints.tight(requestedSize));
145146
child!.layout(childConstraints, parentUsesSize: true);
146147
size = constraints.constrain(child!.size);
148+
149+
if (requestedSize == null) {
150+
// The size is not known yet, let's wait for the next frame.
151+
// This happens e.g. when the widget is animated (e.g. flutter_animate).
152+
// Removing "workaround" will result in a flickering effect where the
153+
// first frame of the animation takes the full size of the LocalHeroScope.
154+
SchedulerBinding.instance.addPostFrameCallback((_) {
155+
markNeedsLayout();
156+
});
157+
}
147158
}
148159

149160
@override

0 commit comments

Comments
 (0)