Skip to content

Conversation

@zensgit
Copy link
Owner

@zensgit zensgit commented Sep 30, 2025

Pre-fetch navigator/messenger, guard mounted after awaits in dialogs and auth screen. Files: widgets/theme_share_dialog.dart, widgets/dialogs/delete_family_dialog.dart, screens/auth/login_screen.dart. Also removes an unused test import. Tests: flutter test all green. Links: #72.

… mounted in ThemeShareDialog, DeleteFamilyDialog, LoginScreen; remove unused test import
… duplicated lines and define messenger/router captures
@Copilot Copilot AI review requested due to automatic review settings September 30, 2025 05:48
@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 应用程序中的上下文管理和代码清理。它通过在异步操作之前预先获取 BuildContext 相关的服务(如 ScaffoldMessengerNavigator)来增强代码的健壮性,从而避免在组件卸载后访问 context 造成的错误。此外,还进行了一些 lint 规则的调整和未使用的代码清理。值得注意的是,此 PR 还包含了一份关于修复 PR #71 CI 问题的详细报告,作为文档记录。

Highlights

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

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 implements Flutter context cleanup improvements by pre-fetching navigator and messenger instances to avoid context access after async operations. The changes focus on preventing potential issues when widgets are unmounted after awaits in dialogs and authentication screens.

  • Pre-fetches Navigator.of(context) and ScaffoldMessenger.of(context) before async operations
  • Replaces context.mounted checks with mounted checks for consistency
  • Removes unused test import and fixes minor const issues

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
jive-flutter/test/transactions/transaction_list_grouping_widget_test.dart Removes unused TransactionCard import
jive-flutter/lib/widgets/theme_share_dialog.dart Pre-fetches messenger, uses mounted checks, fixes const usage
jive-flutter/lib/widgets/states/loading_indicator.dart Removes unnecessary const keywords
jive-flutter/lib/widgets/qr_code_generator.dart Removes unnecessary const keywords
jive-flutter/lib/widgets/dialogs/delete_family_dialog.dart Pre-fetches navigator/messenger, uses mounted checks
jive-flutter/lib/screens/auth/login_screen.dart Pre-fetches messenger/router, uses mounted checks, fixes string interpolation
PR_71_FIX_REPORT.md Adds documentation for previous PR fixes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

SnackBar(
content:
Text('欢迎回来,${result.userData?.username}!'),
content: Text('欢迎回来,\${result.userData?.username}!'),
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

String interpolation is broken due to escaped dollar signs. Remove the backslashes to properly interpolate the variables.

Suggested change
content: Text('欢迎回来,\${result.userData?.username}!'),
content: Text('欢迎回来,${result.userData?.username}!'),

Copilot uses AI. Check for mistakes.

messenger.showSnackBar(
SnackBar(
content: Text('微信登录失败: $error'),
content: Text('微信登录失败: \$error'),
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

String interpolation is broken due to escaped dollar signs. Remove the backslashes to properly interpolate the variables.

Suggested change
content: Text('微信登录失败: \$error'),
content: Text('微信登录失败: $error'),

Copilot uses AI. Check for mistakes.


// 刷新Family列表
ref.refresh(userFamiliesProvider);
final _ = ref.refresh(userFamiliesProvider);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

Using underscore assignments for ignored return values is unnecessary and reduces code clarity. Simply call the methods without assignment: ref.refresh(userFamiliesProvider);

Copilot uses AI. Check for mistakes.

if (!context.mounted) return;
ref.refresh(currentFamilyProvider);
if (!mounted) return;
final _ = ref.refresh(currentFamilyProvider);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

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

Using underscore assignments for ignored return values is unnecessary and reduces code clarity. Simply call the methods without assignment: ref.refresh(userFamiliesProvider);

Copilot uses AI. Check for mistakes.

@zensgit zensgit enabled auto-merge (squash) September 30, 2025 05:50
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

本次 PR 很好地实践了在 await 调用之前捕获依赖 BuildContext 的对象,以避免异步调用后使用 BuildContext 可能引发的问题,这对于应用的健壮性是很好的提升。在 theme_share_dialog.dartdelete_family_dialog.dartlogin_screen.dart 中的修改都很好。不过,我在 login_screen.dart 中发现了几处关键的字符串插值问题,以及在 qr_code_generator.dart 中有一处轻微的性能退步。请查看我的具体评论。

SnackBar(
content:
Text('欢迎回来,${result.userData?.username}!'),
content: Text('欢迎回来,\${result.userData?.username}!'),

Choose a reason for hiding this comment

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

critical

这里的字符串插值被错误地转义了。\${result.userData?.username} 会导致 UI 上显示文字 “${result.userData?.username}” 而不是用户的名字。请移除反斜杠 \ 以修复字符串插值。

Suggested change
content: Text('欢迎回来,\${result.userData?.username}!'),
content: Text('欢迎回来,${result.userData?.username}!'),

messenger.showSnackBar(
SnackBar(
content: Text('微信登录失败: $error'),
content: Text('微信登录失败: \$error'),

Choose a reason for hiding this comment

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

critical

与上一个评论类似,这里的字符串插值 \$error 也被错误地转义了。这会导致 UI 上显示文字 “$error” 而不是实际的错误信息。请移除反斜杠 \

Suggested change
content: Text('微信登录失败: \$error'),
content: Text('微信登录失败: $error'),

Comment on lines 201 to 203
child: Center(
child: const CircularProgressIndicator(),
),

Choose a reason for hiding this comment

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

medium

这里的 Center widget 可以是 const 的,因为它的子 widget CircularProgressIndicatorconst 的。添加 const 关键字可以帮助编译器进行优化,提升性能。

Suggested change
child: Center(
child: const CircularProgressIndicator(),
),
child: const Center(
child: CircularProgressIndicator(),
),

@zensgit zensgit merged commit 7fed2ba into main Oct 8, 2025
7 checks passed
@zensgit zensgit deleted the flutter/context-cleanup-batch5 branch October 8, 2025 02:44
@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