diff --git a/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart b/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart index 244e7e0078..2963348ece 100644 --- a/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart +++ b/packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart @@ -584,8 +584,16 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver } @override - void applyPaintTransform(RenderObject child, Matrix4 transform) { - applyPaintTransformForBoxChild(child as RenderBox, transform); + void applyPaintTransform(RenderBox child, Matrix4 transform) { + if (_keepAliveBucket.containsKey(indexOf(child))) { + // It is possible that widgets under kept alive children want to paint + // themselves. For example, the Material widget tries to paint all + // InkFeatures under its subtree as long as they are not disposed. In + // such case, we give it a zero transform to prevent them from painting. + transform.setZero(); + } else { + applyPaintTransformForBoxChild(child, transform); + } } @override diff --git a/packages/flutter/test/material/tabs_test.dart b/packages/flutter/test/material/tabs_test.dart index 4dbdbc7bc3..052563acdd 100644 --- a/packages/flutter/test/material/tabs_test.dart +++ b/packages/flutter/test/material/tabs_test.dart @@ -1059,6 +1059,43 @@ void main() { expect(_mainTabController.index, 2); }); + testWidgets('TabBarView can warp when child is kept alive and contains ink', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/57662. + final TabController controller = TabController( + vsync: const TestVSync(), + length: 3, + ); + + await tester.pumpWidget( + boilerplate( + child: TabBarView( + controller: controller, + children: const [ + Text('Page 1'), + Text('Page 2'), + KeepAliveInk('Page 3'), + ], + ), + ), + ); + + expect(controller.index, equals(0)); + expect(find.text('Page 1'), findsOneWidget); + expect(find.text('Page 3'), findsNothing); + + controller.index = 2; + await tester.pumpAndSettle(); + expect(find.text('Page 1'), findsNothing); + expect(find.text('Page 3'), findsOneWidget); + + controller.index = 0; + await tester.pumpAndSettle(); + expect(find.text('Page 1'), findsOneWidget); + expect(find.text('Page 3'), findsNothing); + + expect(tester.takeException(), isNull); + }); + testWidgets('TabBarView scrolls end close to a new page with custom physics', (WidgetTester tester) async { final TabController tabController = TabController( vsync: const TestVSync(), @@ -2634,3 +2671,25 @@ void main() { expect(pageView.physics.toString().contains('ClampingScrollPhysics'), isFalse); }); } + +class KeepAliveInk extends StatefulWidget { + const KeepAliveInk(this.title, {Key key}) : super(key: key); + final String title; + @override + State createState() { + return _KeepAliveInkState(); + } +} + +class _KeepAliveInkState extends State with AutomaticKeepAliveClientMixin { + @override + Widget build(BuildContext context) { + super.build(context); + return Ink( + child: Text(widget.title), + ); + } + + @override + bool get wantKeepAlive => true; +}