-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Migrate to list and builder Sliver convenience constructors #173011
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
Migrate to list and builder Sliver convenience constructors #173011
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| /// @docImport 'scroll_delegate.dart'; |
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.
This makes the doc references to SliverChildBuilderDelegate work below.
| itemCount: 10, | ||
| itemBuilder: (BuildContext context, int index) { | ||
| return SizedBox(height: itemHeight, child: Text('Item ${-index - 1}')); | ||
| }, |
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 should've used SliverList.list here to exactly match the previous behavior. However, whether these widgets are built lazily or eagerly does not appear to affect the test, and, using SliverList.builder reduces boilerplate. Let me know if you'd like me to switch to SliverList.list though!
| (int index) => SizedBox(height: 50, child: Text('Tile $index')), | ||
| ), | ||
| ), | ||
| SliverList.builder( |
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 also switched to SliverList.builder here, let me know if you'd prefer I use SliverList.list here instead.
| return SizedBox(height: 100.0, child: Text('Tile $i')); | ||
| }), | ||
| ), | ||
| SliverList.builder( |
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.
Here as well
| return Chip(key: Key(item), label: Text('Tile $item')); | ||
| }).toList(), | ||
| ), | ||
| SliverList.builder( |
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.
Here as well
| for (int i = 0; i < 50; i++) | ||
| SizedBox(height: 200, child: Center(child: Text('Item $i'))), | ||
| ]), | ||
| SliverList.builder( |
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.
Here as well
| (int index) => SizedBox(height: 100.0, child: Text('B$index')), | ||
| ), | ||
| ), | ||
| sliver: SliverList.builder( |
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.
Here as well
1040397 to
372c593
Compare
Piinks
left a comment
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.
Me the other day, "The constructors were added not too long ago..."
PR description: "In 2022, we introduced..."
🙃 🫠 What is time.
This is awesome, thank you. The places where you refactored for clarity and conciseness LGTM. However, for those under examples/api, there is a description that might contradict the updated snippets. The description immediately follows the {@tool dartpad}, can you check that they still make sense with the updated samples? I think most should be ok.
I did a pass to check that descriptions of all |
3ffdf30 to
5c9093d
Compare
Piinks
left a comment
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 did a pass to check that descriptions of all {@tool dartpad} that link an example touched by this PR - they all looked good!
Thank you! 🙏
LGTM!
|
FYI, I also checked the flutter/website repo this morning - that doesn't have any unnecessary references to sliver delegates, so no need to send a PR for that repo. |
…173011) In 2022, we introduced new convenience constructors like `SliverList.builder` and `SliverList.list`. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :) I migrated 80% of the code by hand, and 20% using Gemini CLI. See [go/loic-ai-log](http://goto.google.com/loic-ai-log) (Google internal) for details. There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues: 1. flutter#173018 2. flutter#173019 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…173011) In 2022, we introduced new convenience constructors like `SliverList.builder` and `SliverList.list`. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :) I migrated 80% of the code by hand, and 20% using Gemini CLI. See [go/loic-ai-log](http://goto.google.com/loic-ai-log) (Google internal) for details. There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues: 1. flutter#173018 2. flutter#173019 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…173011) In 2022, we introduced new convenience constructors like `SliverList.builder` and `SliverList.list`. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :) I migrated 80% of the code by hand, and 20% using Gemini CLI. See [go/loic-ai-log](http://goto.google.com/loic-ai-log) (Google internal) for details. There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues: 1. flutter#173018 2. flutter#173019 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…173011) In 2022, we introduced new convenience constructors like `SliverList.builder` and `SliverList.list`. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :) I migrated 80% of the code by hand, and 20% using Gemini CLI. See [go/loic-ai-log](http://goto.google.com/loic-ai-log) (Google internal) for details. There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues: 1. flutter#173018 2. flutter#173019 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…173011) In 2022, we introduced new convenience constructors like `SliverList.builder` and `SliverList.list`. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :) I migrated 80% of the code by hand, and 20% using Gemini CLI. See [go/loic-ai-log](http://goto.google.com/loic-ai-log) (Google internal) for details. There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues: 1. flutter#173018 2. flutter#173019 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
In 2022, we introduced new convenience constructors like
SliverList.builderandSliverList.list. Unfortunately, LLMs like Gemini seem to prefer the delegate pattern even when these convenience constructors are usable. This updates Flutter's docs, code, and tests to use these convenience constructors where possible. Hopefully this will nudge LLMs to consider using the new APIs :)I migrated 80% of the code by hand, and 20% using Gemini CLI. See go/loic-ai-log (Google internal) for details.
There's a few locations that I wasn't able to migrate to the convenience constructors due to missing APIs. I filed the following issues:
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.