Skip to content

Conversation

@zensgit
Copy link
Owner

@zensgit zensgit commented Sep 30, 2025

  • accept_invitation_dialog: capture messenger/navigator; mounted guards; remove unused import
  • delete_family_dialog: capture messenger/navigator; use mounted; underscore ref.refresh; switch navigator/messenger usages
  • loading_indicator/qr_code_generator: remove invalid consts

All tests green locally; analyzer warnings reduced; remaining warnings tracked separately.

…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
@Copilot Copilot AI review requested due to automatic review settings September 30, 2025 06:02
@zensgit zensgit enabled auto-merge (squash) September 30, 2025 06:02
Copy link

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 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.

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

此拉取请求主要侧重于 Flutter 对话框中的上下文清理和代码优化。它通过在异步操作前捕获 ScaffoldMessengerNavigator 实例,并统一使用 mounted 属性来确保 BuildContext 的安全使用,从而提高了 AcceptInvitationDialogDeleteFamilyDialog 的健壮性。此外,还修正了 LoadingIndicatorQrCodeGenerator 中不正确的 const 关键字使用,以符合 Flutter 的最佳实践,并减少了代码中的分析器警告。

Highlights

  • 上下文安全改进: 在 AcceptInvitationDialogDeleteFamilyDialog 中,在异步操作前捕获 ScaffoldMessengerNavigator 实例,以避免在 BuildContext 不再有效时使用它。
  • mounted 检查统一: 将 context.mounted 检查统一为使用 mounted 属性,以确保组件在操作期间仍然挂载。
  • const 关键字清理: 移除了 LoadingIndicatorQrCodeGenerator 中不正确的 const 关键字使用,这些 const 关键字应用于包含非常量表达式的 widget。
  • 代码精简: 移除了 AcceptInvitationDialog 中未使用的 snackbar_utils 导入和 currentUser 变量。
  • Provider 刷新优化: 在 DeleteFamilyDialog 中,将 ref.refresh 调用改为 final _ = ref.refresh,以明确其副作用并避免潜在的 lint 警告。
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 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.

Comment on lines +76 to 82
final messengerErr = ScaffoldMessenger.of(context);
messengerErr.showSnackBar(
SnackBar(
content: Text('接受邀请失败: ${e.toString()}'),
backgroundColor: Colors.red,
),
);

Choose a reason for hiding this comment

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

medium

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),

Choose a reason for hiding this comment

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

medium

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.

Suggested change
SizedBox(height: 16),
const SizedBox(height: 16),

@zensgit zensgit merged commit 8ecc8ca into main Sep 30, 2025
9 checks passed
@zensgit zensgit deleted the flutter/context-cleanup-batch7 branch September 30, 2025 07:04
@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