Fix avoid_context_read_in_build false positive on non-widget-returning callbacks - #566
Merged
PiotrRogulski merged 4 commits intoAug 15, 2026
Merged
Conversation
…lbacks context.read() inside a provider's create callback (BlocProvider, RepositoryProvider, Provider, ...) was being flagged even though create runs lazily once to construct the provided value, not on every rebuild, making read() the correct choice there. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
Replace the class-name-based special case for provider create callbacks with a general rule: a BuildContext-taking closure only counts as running during build if it actually produces a Widget. Non-widget- returning callbacks (create, or any other lazy factory) are exempt regardless of parameter name or enclosing widget name. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FadFXZpP7Bzd3yPQwNorQZ
PiotrRogulski
marked this pull request as ready for review
August 14, 2026 21:55
cupofme
approved these changes
Aug 15, 2026
PiotrRogulski
deleted the
claude/context-read-build-false-positive-ybv13m
branch
August 15, 2026 08:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
avoid_context_read_in_buildwas flaggingcontext.readinside a provider'screatecallback (e.g.BlocProvider(create: (context) => MyCubit(repo: context.read()))), even thoughcreateruns lazily once rather than on every rebuild.BuildContext-taking closure is now only treated as running during build if it also returns aWidget. Non-widget-returning closures (a provider'screate, or any other lazy factory) are exempt regardless of the callback's name or the enclosing widget's name.Test plan
dart testonpackages/leancode_lint— 253/253 passingdart analyze— no issuesdart format --set-exit-if-changed— no changes neededGenerated by Claude Code