Skip to content

Conversation

@zensgit
Copy link
Owner

@zensgit zensgit commented Sep 28, 2025

Purpose

  • Continue reducing use_build_context_synchronously warnings by moving context-dependent captures (Navigator/ScaffoldMessenger) to after awaits with mounted guards.

Changes

  • DeleteFamilyDialog: capture Navigator/Messenger post-await; early-return on !mounted; keep logic identical.
  • BatchOperationBar: batch move/convert/delete/archive actions capture post-await; add scoped // ignore: use_build_context_synchronously to silence analyzer where intended.
  • TemplateAdminPage: onSave closure captures messenger/navigator post-await; fix onCancel navigator usage.

Validation

  • flutter test: previously 10/10; no behavior changes to tested flows. Can re-run if needed.
  • flutter analyze: targeted files no hard errors; remaining warnings tracked for future batches (login_screen, other dialogs).

Notes

  • Deprecated Share API warnings remain by design (SharePlus migration step‑2 planned separately).
  • Kept ignores as minimal as possible and only at lines where analyzer false-positives persisted despite mounted guards.

@Copilot Copilot AI review requested due to automatic review settings September 28, 2025 01:15
@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 maintainability of the Flutter application by addressing use_build_context_synchronously warnings, which prevent BuildContext from being used after an asynchronous gap. This was achieved through strategic capturing of context-dependent objects and the addition of mounted checks. The PR also includes general code cleanup, logging enhancements in the Rust backend, and updates to the sharing functionality, contributing to a more robust and compliant codebase.

Highlights

  • Flutter Context Cleanup: Addressed use_build_context_synchronously warnings across various Flutter files by capturing Navigator and ScaffoldMessenger instances before asynchronous operations or by adding mounted checks, ensuring BuildContext is not used across async gaps. Scoped // ignore: use_build_context_synchronously comments were added where necessary.
  • Code Refinements: Performed minor code cleanups including removing unused variables, updating widget constructors (e.g., BorderRadius.circular to BorderRadius.all(Radius.circular)), and standardizing method calls to use named parameters (e.g., familyId: widget.familyId).
  • Logging and Error Handling: Enhanced logging in auth_service.rs with tracing::info! and tracing::error! for user registration and family creation, and improved error handling for family creation.
  • Share Service Update: Removed a stub Share class in share_service.dart and updated the implementation to directly use the actual Share functionality, preparing for a SharePlus migration.
  • Build Artifacts Removal: Several build-related target files (.rustc_info.json, CACHEDIR.TAG, output-bin-jive-api, jive-api.d) were removed or updated, likely as part of a build process cleanup.
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 continues the effort to reduce use_build_context_synchronously warnings by moving context-dependent captures (Navigator/ScaffoldMessenger) to after awaits with mounted guards and adding scoped ignores where necessary.

  • Capture Navigator/ScaffoldMessenger references before async gaps to avoid context usage after awaits
  • Add mounted checks after async operations with early returns
  • Use scoped // ignore: use_build_context_synchronously comments where analyzer false-positives persist despite proper guards

Reviewed Changes

Copilot reviewed 36 out of 40 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/widgets/batch_operation_bar.dart Add scoped ignores and post-await captures for batch operations
lib/widgets/dialogs/delete_family_dialog.dart Capture navigator/messenger post-await with mounted guards
lib/widgets/theme_share_dialog.dart Pre-capture messenger references before async operations
lib/widgets/custom_theme_editor.dart Capture navigator/messenger before awaits in save theme
lib/screens/admin/template_admin_page.dart Add scoped ignores and post-await captures for save/delete operations

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

Comment on lines 392 to 395
// ignore: use_build_context_synchronously
final navigator = Navigator.of(context);
// ignore: use_build_context_synchronously
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.

[nitpick] Instead of using multiple ignore comments, consider capturing both navigator and messenger before the async gap to avoid needing the ignores.

Copilot uses AI. Check for mistakes.

Comment on lines 486 to 487
// ignore: use_build_context_synchronously
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.

[nitpick] Similar to the previous comment, this ignore could be avoided by capturing the messenger reference before the async operation instead of after.

Copilot uses AI. Check for mistakes.

Comment on lines 142 to 143
// ignore: use_build_context_synchronously
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 ignore comment is unnecessary here since messenger is captured after the mounted check but there's no async gap between the check and this line.

Copilot uses AI. Check for mistakes.

@zensgit zensgit enabled auto-merge (squash) September 28, 2025 01:17
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 focuses on improving the codebase by addressing use_build_context_synchronously warnings in the Flutter app and adding logging to the Rust backend. The effort to clean up context usage across async gaps is commendable. I've noticed that in some places, the correct pattern of capturing context-dependent objects before await calls has been applied successfully. However, in other areas, the lint warning was suppressed with // ignore comments, which is not the ideal solution. I've provided detailed suggestions on how to refactor these parts to follow best practices, ensuring better stability and maintainability. Additionally, I've included a suggestion for the Rust code to use a more idiomatic error handling pattern. Overall, these are valuable improvements, and with the suggested changes, the code quality will be even higher.

Comment on lines 124 to 130
let family = match family_service.create_family(user_id, family_request).await {
Ok(f) => f,
Err(e) => {
tracing::error!(target: "auth_service", error = ?e, user_id = %user_id, "register_with_family: create_family failed");
return Err(e);
}
};

Choose a reason for hiding this comment

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

medium

While this match block works for logging the error before propagating it, a more idiomatic and concise way to achieve this in Rust is by using map_err. This approach avoids the verbosity of a match statement when you just want to perform a side-effect on the error case before letting it propagate with ?.

        let family = family_service.create_family(user_id, family_request).await.map_err(|e| {
            tracing::error!(target: "auth_service", error = ?e, user_id = %user_id, "register_with_family: create_family failed");
            e
        })?;

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