From f3d95cd734ad23b7f9e15e7d0bc182d40965e05f Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 24 Mar 2020 09:55:47 -0700 Subject: [PATCH] Revert "Fix RefreshIndicator performance issue (#47667)" (#53149) This reverts commit 602ac0bc10c9783c4bb94ba8583ee2765a3cc313. --- .../lib/src/material/refresh_indicator.dart | 22 +++++------ .../test/material/refresh_indicator_test.dart | 37 +------------------ 2 files changed, 12 insertions(+), 47 deletions(-) diff --git a/packages/flutter/lib/src/material/refresh_indicator.dart b/packages/flutter/lib/src/material/refresh_indicator.dart index 85212839c4..d63b33a2ea 100644 --- a/packages/flutter/lib/src/material/refresh_indicator.dart +++ b/packages/flutter/lib/src/material/refresh_indicator.dart @@ -409,26 +409,26 @@ class RefreshIndicatorState extends State with TickerProviderS return _pendingRefreshFuture; } + final GlobalKey _key = GlobalKey(); + @override Widget build(BuildContext context) { assert(debugCheckHasMaterialLocalizations(context)); final Widget child = NotificationListener( + key: _key, onNotification: _handleScrollNotification, child: NotificationListener( onNotification: _handleGlowNotification, child: widget.child, ), ); - assert(() { - if (_mode == null) { - assert(_dragOffset == null); - assert(_isIndicatorAtTop == null); - } else { - assert(_dragOffset != null); - assert(_isIndicatorAtTop != null); - } - return true; - }()); + if (_mode == null) { + assert(_dragOffset == null); + assert(_isIndicatorAtTop == null); + return child; + } + assert(_dragOffset != null); + assert(_isIndicatorAtTop != null); final bool showIndeterminateIndicator = _mode == _RefreshIndicatorMode.refresh || _mode == _RefreshIndicatorMode.done; @@ -436,7 +436,7 @@ class RefreshIndicatorState extends State with TickerProviderS return Stack( children: [ child, - if (_mode != null) Positioned( + Positioned( top: _isIndicatorAtTop ? 0.0 : null, bottom: !_isIndicatorAtTop ? 0.0 : null, left: 0.0, diff --git a/packages/flutter/test/material/refresh_indicator_test.dart b/packages/flutter/test/material/refresh_indicator_test.dart index 17a5da2714..b24097e62a 100644 --- a/packages/flutter/test/material/refresh_indicator_test.dart +++ b/packages/flutter/test/material/refresh_indicator_test.dart @@ -420,39 +420,4 @@ void main() { expect(controller.offset, lessThan(0.0)); expect(refreshCalled, isTrue); }, variant: const TargetPlatformVariant({ TargetPlatform.iOS, TargetPlatform.macOS })); - - testWidgets('RefreshIndicator does not force child to relayout', (WidgetTester tester) async { - int layoutCount = 0; - - Widget layoutCallback(BuildContext context, BoxConstraints constraints) { - layoutCount++; - return ListView( - physics: const AlwaysScrollableScrollPhysics(), - children: ['A', 'B', 'C', 'D', 'E', 'F'].map((String item) { - return SizedBox( - height: 200.0, - child: Text(item), - ); - }).toList(), - ); - } - - await tester.pumpWidget( - MaterialApp( - home: RefreshIndicator( - onRefresh: refresh, - child: LayoutBuilder(builder: layoutCallback), - ), - ), - ); - - await tester.fling(find.text('A'), const Offset(0.0, 300.0), 1000.0); // trigger refresh - await tester.pump(); - - await tester.pump(const Duration(seconds: 1)); // finish the scroll animation - await tester.pump(const Duration(seconds: 1)); // finish the indicator settle animation - await tester.pump(const Duration(seconds: 1)); // finish the indicator hide animation - - expect(layoutCount, 1); - }); -} \ No newline at end of file +}