-
Notifications
You must be signed in to change notification settings - Fork 27.2k
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
Fix RefreshIndicator performance issue #47667
Fix RefreshIndicator performance issue #47667
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
@googlebot I fixed it. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some benchmark that this will improve? If not, we should write one before landing this.
If we don't have a benchmark for it, it will very easily get regressed (it will also be harder to tell if or how much this actually improves performance).
Hi @christian-muertz great job spotting this issue and thank you for the fix! However we can't merge the pull request without a valid test. I think a good test to add would be one that verifies |
Yes iam still interested. I will take a look at it again on friday! |
Hi @christian-muertz, any updates on this? |
No, i currently have no idea how to test whether the child was relayout. |
Does something like this make sense (the code snippet makes use of some global variables in refresh_indicator_test.dart)? testWidgets(
'RefreshIndicator does not force child to relayout',
(WidgetTester tester) async {
refreshCalled = false;
int layoutCount = 0;
Widget layoutCallback(BuildContext context, BoxConstraints constraints) {
layoutCount += 1;
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);
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(refreshCalled, true);
expect(layoutCount, 1);
}); |
Yes it does make sense. I would suggest not checking for it to refresh because that is not what the test is for. I will add a test like this in a few mins :D |
883f37a
to
658afeb
Compare
} else { | ||
assert(_dragOffset != null); | ||
assert(_isIndicatorAtTop != null); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be a return true;
?
Alternatively:
assert((_dragOffset == null) == (_mode == null));
assert((_isIndicatorAtTop == null) == (_mode == null));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'll add a return true . I think its easier to understand !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
int layoutCount = 0; | ||
|
||
Widget layoutCallback(BuildContext context, BoxConstraints constraints) { | ||
layoutCount++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: our style guide prefers +=
over ++
: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#prefer--over-
@dnfield it seems the change does prevent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Nope, this works too (we can test that we're not doing the extra work we don't need to do). |
Description
Fixes the performance issue described by #47664.
Related Issues
-Fixes #47664
Tests
I added the following tests: /
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.