-
Notifications
You must be signed in to change notification settings - Fork 0
flutter: context cleanup batch 1 + const-eval fixes #59
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
zensgit
commented
Sep 28, 2025
- Fix BuildContext after await: right_click_copy (capture messenger + refactor copy), custom_theme_editor (use local messenger)\n- Fix const-eval issues: currency_converter, color_picker_dialog, refreshable_list\n- Analyzer: no hard errors; tests previously green (UI-only changes)\n\nFollow-ups:\n- Continue context cleanup (theme_share_dialog, delete_family_dialog refresh usage)\n- Optional: tidy remaining prefer_const_constructors infos in color_picker_dialog
…nce.share/shareXFiles in QR + ShareService; remove local stub
…hare_plus directly
…g and DeleteFamilyDialog
…or) + fix const-eval in common widgets
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 addresses BuildContext usage after await operations and fixes const-eval issues across multiple Flutter widgets and dialogs. The changes ensure proper Flutter best practices by capturing UI handles before async operations and removing unnecessary const keywords where dynamic values are used.
Key changes:
- Fixed BuildContext usage after await by capturing Navigator and ScaffoldMessenger before async operations
- Removed const keywords from widgets that use dynamic/runtime values
- Cleaned up stub implementations and unused imports
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| qr_code_generator.dart | Removed const from Center widgets and cleaned up stub XFile implementations |
| delete_family_dialog.dart | Captured navigator and messenger before async deleteFamily operation |
| accept_invitation_dialog.dart | Fixed context usage after await and replaced SnackbarUtils with direct messenger calls |
| custom_theme_editor.dart | Captured UI handles before async operations in theme saving |
| currency_converter.dart | Removed const from SizedBox containing dynamic CircularProgressIndicator |
| right_click_copy.dart | Refactored copy method to use captured messenger instead of context after await |
| refreshable_list.dart | Removed const from SizedBox widgets that access MediaQuery context |
| color_picker_dialog.dart | Removed const from SizedBox with dynamic text content |
| share_service.dart | Cleaned up stub Share class and simplified shareXFiles call |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| SnackbarUtils.showError( | ||
| context, | ||
| '接受邀请失败: ${e.toString()}', | ||
| final messenger = ScaffoldMessenger.of(context); |
Copilot
AI
Sep 28, 2025
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.
The messenger is already captured at line 53 before the async operation. This redundant capture in the catch block should use the previously captured messenger variable instead of accessing context again.
| final messenger = ScaffoldMessenger.of(context); |
Copilot uses AI. Check for mistakes.
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! This pull request focuses on improving the stability and correctness of the Flutter application by addressing common issues related to 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 does a good job of cleaning up the codebase by addressing use_build_context_synchronously lint warnings and fixing several const-eval errors. The approach of capturing context-dependent objects like Navigator and ScaffoldMessenger before asynchronous calls is correct and improves the robustness of the UI code.
My review includes a couple of high-severity comments related to the scope of these captured objects in try...catch blocks. In accept_invitation_dialog.dart and delete_family_dialog.dart, the captured variables are declared inside the try block, which makes them inaccessible in the catch block, partially defeating the purpose of the refactoring. I've provided suggestions to correct this scoping issue.
Overall, these are valuable improvements to the code quality and stability. Keep up the great work!
| // Capture UI handles before async work | ||
| final navigator = Navigator.of(context); | ||
| final messenger = ScaffoldMessenger.of(context); |
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.
Similar to the other dialogs, you're capturing navigator and messenger inside the try block. This is a good practice to avoid using BuildContext across async gaps, but their scope is limited to the try block. This means they are not available in the catch block, where you would need them to show an error message safely.
To fix this, please move these declarations to before the try block and update the catch block to use the captured messenger.
…pture and fix duplicates
Resolved conflicts in: - share_service.dart - account_list.dart - transaction_list.dart - batch_operation_bar.dart - right_click_copy.dart - qr_code_generator.dart - custom_theme_editor.dart - theme_share_dialog.dart - accept_invitation_dialog.dart - delete_family_dialog.dart