Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reland "Fix RefreshIndicator performance issue" #53206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions packages/flutter/lib/src/material/refresh_indicator.dart
Expand Up @@ -409,34 +409,34 @@ class RefreshIndicatorState extends State<RefreshIndicator> with TickerProviderS
return _pendingRefreshFuture;
}

final GlobalKey _key = GlobalKey();

@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterialLocalizations(context));
final Widget child = NotificationListener<ScrollNotification>(
key: _key,
onNotification: _handleScrollNotification,
child: NotificationListener<OverscrollIndicatorNotification>(
onNotification: _handleGlowNotification,
child: widget.child,
),
);
if (_mode == null) {
assert(_dragOffset == null);
assert(_isIndicatorAtTop == null);
return child;
}
assert(_dragOffset != null);
assert(_isIndicatorAtTop != null);
assert(() {
if (_mode == null) {
assert(_dragOffset == null);
assert(_isIndicatorAtTop == null);
} else {
assert(_dragOffset != null);
assert(_isIndicatorAtTop != null);
}
return true;
}());

final bool showIndeterminateIndicator =
_mode == _RefreshIndicatorMode.refresh || _mode == _RefreshIndicatorMode.done;

return Stack(
children: <Widget>[
child,
Positioned(
if (_mode != null) Positioned(
top: _isIndicatorAtTop ? 0.0 : null,
bottom: !_isIndicatorAtTop ? 0.0 : null,
left: 0.0,
Expand Down
37 changes: 36 additions & 1 deletion packages/flutter/test/material/refresh_indicator_test.dart
Expand Up @@ -420,4 +420,39 @@ void main() {
expect(controller.offset, lessThan(0.0));
expect(refreshCalled, isTrue);
}, variant: const TargetPlatformVariant(<TargetPlatform>{ 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: <String>['A', 'B', 'C', 'D', 'E', 'F'].map<Widget>((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);
});
}