Unverified Commit 8037677d authored by fzyzcjy's avatar fzyzcjy Committed by GitHub

Fix `FollowerLayer` (`CompositedTransformFollower`) has null pointer error...

Fix `FollowerLayer` (`CompositedTransformFollower`) has null pointer error when using with some kinds of `Layer`s (#100672)
parent a63ee24b
......@@ -2553,13 +2553,13 @@ class FollowerLayer extends ContainerLayer {
}
_establishTransform();
if (_lastTransform != null) {
_lastOffset = unlinkedOffset;
engineLayer = builder.pushTransform(
_lastTransform!.storage,
oldLayer: _engineLayer as ui.TransformEngineLayer?,
);
addChildrenToScene(builder);
builder.pop();
_lastOffset = unlinkedOffset;
} else {
_lastOffset = null;
final Matrix4 matrix = Matrix4.translationValues(unlinkedOffset!.dx, unlinkedOffset!.dy, .0);
......
......@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -318,4 +321,63 @@ void main() {
contains('LeaderLayer anchor must come before FollowerLayer in paint order'),
);
});
testWidgets(
'`FollowerLayer` (`CompositedTransformFollower`) has null pointer error when using with some kinds of `Layer`s',
(WidgetTester tester) async {
final LayerLink link = LayerLink();
await tester.pumpWidget(
CompositedTransformTarget(
link: link,
child: CompositedTransformFollower(
link: link,
child: const _CustomWidget(),
),
),
);
});
}
class _CustomWidget extends SingleChildRenderObjectWidget {
const _CustomWidget({Key? key, Widget? child}) : super(key: key, child: child);
@override
_CustomRenderObject createRenderObject(BuildContext context) => _CustomRenderObject();
@override
void updateRenderObject(BuildContext context, _CustomRenderObject renderObject) {}
}
class _CustomRenderObject extends RenderProxyBox {
_CustomRenderObject({RenderBox? child}) : super(child);
@override
void paint(PaintingContext context, Offset offset) {
if (layer == null) {
layer = _CustomLayer(
computeSomething: _computeSomething,
);
} else {
(layer as _CustomLayer?)?.computeSomething = _computeSomething;
}
context.pushLayer(layer!, super.paint, Offset.zero);
}
void _computeSomething() {
// indeed, use `globalToLocal` to compute some useful data
globalToLocal(Offset.zero);
}
}
class _CustomLayer extends ContainerLayer {
_CustomLayer({required this.computeSomething});
VoidCallback computeSomething;
@override
void addToScene(ui.SceneBuilder builder) {
computeSomething(); // indeed, need to use result of this function
super.addToScene(builder);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment