From 62378a3755e0cd7cbc20f2c33a068cec51d92dd1 Mon Sep 17 00:00:00 2001 From: chunhtai <47866232+chunhtai@users.noreply.github.com> Date: Wed, 24 Jun 2020 13:53:01 -0700 Subject: [PATCH] =?UTF-8?q?fix=20ink=20feature=20tries=20to=20get=20parent?= =?UTF-8?q?=20transformations=20when=20it=20is=20in=20the=E2=80=A6=20(#601?= =?UTF-8?q?29)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rendering/sliver_multi_box_adaptor.dart | 12 +++- packages/flutter/test/material/tabs_test.dart | 59 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) 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; +}