Skip to content

Conversation

zensgit
Copy link
Owner

@zensgit 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

@Copilot Copilot AI review requested due to automatic review settings September 28, 2025 00:24
Copy link

@Copilot Copilot AI left a 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);
Copy link

Copilot AI Sep 28, 2025

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.

Suggested change
final messenger = ScaffoldMessenger.of(context);

Copilot uses AI. Check for mistakes.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 BuildContext usage in asynchronous code and resolving const-evaluation errors. It also includes cleanup of temporary stub implementations and refactoring of snackbar display logic, contributing to a more robust and maintainable codebase.

Highlights

  • BuildContext Usage After Await: Refactored several widgets to correctly handle BuildContext across asynchronous operations. This involves capturing ScaffoldMessengerState and NavigatorState instances before await calls to ensure they are used safely, preventing potential runtime errors if the widget is unmounted during the async gap. Affected components include RightClickCopy, CustomThemeEditor, AcceptInvitationDialog, and DeleteFamilyDialog.
  • Const-Evaluation Fixes: Addressed multiple const-eval issues by removing unnecessary const keywords from widgets like SizedBox, Center, and CircularProgressIndicator where their children or properties are not constant. This ensures proper widget tree reconstruction and avoids potential build errors. Files updated include CurrencyConverter, ColorPickerDialog, RefreshableList, and QrCodeGenerator.
  • Stub Code Removal: Cleaned up temporary stub implementations for Share and XFile classes in share_service.dart and qr_code_generator.dart. This indicates that the actual sharing functionality or external dependencies are now properly integrated or no longer require these placeholders.
  • Snackbar Utility Refactoring: In AcceptInvitationDialog, the custom SnackbarUtils helper was replaced with direct calls to ScaffoldMessenger.showSnackBar. This streamlines snackbar presentation and aligns with standard Flutter practices.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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!

Comment on lines +80 to +82
// Capture UI handles before async work
final navigator = Navigator.of(context);
final messenger = ScaffoldMessenger.of(context);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

@zensgit zensgit enabled auto-merge (squash) September 28, 2025 00:32
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
@zensgit zensgit merged commit de373a5 into main Oct 8, 2025
7 checks passed
@zensgit zensgit deleted the flutter/context-cleanup-batch1 branch October 8, 2025 02:52
@zensgit zensgit mentioned this pull request Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant