-
Notifications
You must be signed in to change notification settings - Fork 0
flutter: context cleanup batch 7 — accept invitation + delete family + loading/qr const cleanup #77
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
Conversation
…essenger/navigator, remove unused var, fix syntax; use mounted guard
… remove invalid consts in LoadingIndicator/QRCode widget
…nger/navigator; ref.refresh underscores; accept_invitation remove unused import
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.
Pull Request Overview
This PR performs context cleanup in Flutter dialog and widget components to improve code quality and reduce analyzer warnings. The changes focus on capturing Navigator and ScaffoldMessenger instances early, using proper mounted guards, and removing invalid const keywords.
- Capture Navigator and ScaffoldMessenger instances to avoid context usage after disposal
- Replace context.mounted checks with proper mounted property usage
- Remove unnecessary const keywords from widgets with dynamic properties
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| loading_indicator.dart | Remove invalid const keywords from SizedBox widgets that have dynamic properties |
| qr_code_generator.dart | Remove const keywords from Center and CircularProgressIndicator widgets |
| delete_family_dialog.dart | Capture navigator/messenger early, use mounted guards, and underscore unused refresh results |
| accept_invitation_dialog.dart | Remove unused import, capture messenger/navigator, and replace utility calls with direct SnackBar usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Summary of ChangesHello @zensgit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 此拉取请求主要侧重于 Flutter 对话框中的上下文清理和代码优化。它通过在异步操作前捕获 Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request effectively cleans up BuildContext usage by capturing navigator and messenger instances before async gaps, and also removes several invalid const keywords, which improves code correctness and adheres to best practices. The changes are well-executed. I have a couple of suggestions to further enhance the code's consistency and performance.
| final messengerErr = ScaffoldMessenger.of(context); | ||
| messengerErr.showSnackBar( | ||
| SnackBar( | ||
| content: Text('接受邀请失败: ${e.toString()}'), | ||
| backgroundColor: Colors.red, | ||
| ), | ||
| ); |
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.
While this is safe because of the mounted check, to be more consistent with the goal of this PR (capturing context-dependent objects before async gaps), you could define messenger before the try block. This would allow you to reuse it here in the catch block, avoiding another call to ScaffoldMessenger.of(context) and making the code cleaner.
Example:
// In _acceptInvitation() method, before the try block
final messenger = ScaffoldMessenger.of(context);
final navigator = Navigator.of(context);
try {
// ... async operations
} catch (e) {
if (mounted) {
messenger.showSnackBar(
SnackBar(
content: Text('接受邀请失败: ${e.toString()}'),
backgroundColor: Colors.red,
),
);
}
}
// ...| ), | ||
| if (message != null) ...[ | ||
| const SizedBox(height: 16), | ||
| SizedBox(height: 16), |
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 SizedBox can be a const constructor. Using const where possible is a Flutter best practice for performance optimization, as it helps avoid unnecessary widget rebuilds. Since this PR is focused on const cleanup, it would be good to ensure we are using const where it is valid.
| SizedBox(height: 16), | |
| const SizedBox(height: 16), |
All tests green locally; analyzer warnings reduced; remaining warnings tracked separately.