Repository navigation
Conversation
Returns the non-null data when dataReady is true and throws a descriptive StateError otherwise, so callers no longer need the null assertion operator after checking dataReady. Closes #1118 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
LCOV of commit
|
| Metric | Coverage | Details |
|---|---|---|
| 📈 Lines | 🔴 7.7% | 283 / 3692 lines |
| 🔧 Functions | ⚪ N/A | no data found |
| 🌿 Branches | ⚪ N/A | no data found |
📁 Files Changed Coverage
| File | Lines | Functions | Branches |
|---|---|---|---|
lib/src/code_generation/router_annotation/extended_navigator.dart |
⚪ – (0) | ⚪ – (0) | ⚪ – (0) |
lib/src/view_models/helpers/data_state_helper.dart |
🔴 0.0% (8) | ⚪ – (0) | ⚪ – (0) |
🟢 ≥ 90% · 🟡 ≥ 70% · 🔴 below 70% · ⚪ no data
Full coverage report
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ferrarafer
approved these changes
Sep 19, 2026
ferrarafer
left a comment
Contributor
There was a problem hiding this comment.
Looks good, thanks! The getter only returns when dataReady is true, so the cast is safe, and existing callers aren't affected.
One thing to be aware of: safeData throws while the view model is busy, even when valid data is already loaded (for example when a FutureViewModel re-runs initialise(), or a StreamViewModel runs another action through runBusyFuture). So views that keep showing the previous data during a refresh should keep using data. This matches how dataReady already behaves, so no change is needed.
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
Adds a
safeDatagetter toDataStateHelper<T>(used byFutureViewModelandStreamViewModel).dataisT?because it starts unset and is cleared on error, so Dart cannot promote it to non-null even right after adataReadycheck. Callers end up writingdata!everywhere.safeDataperforms thedataReadycheck itself and returns a non-nullT, or throws a descriptiveStateErrorpointing the caller atdataReady/isBusy/hasError.This is the accessor agreed on in the issue thread; the requested PR was never submitted.
Changes
lib/src/view_models/helpers/data_state_helper.dart: newT get safeDatawith dartdoc. ExistingdataanddataReadyare untouched.test/data_state_helper_test.dart: 8 tests covering ready, never set, busy, error, error message content, and nullableTbehaviour.Notes
MultipleFutureViewModel/MultipleStreamViewModelwere left alone: theirdataMapisMap<K, dynamic>?on a private base class, so a keyedsafeDatawould give no type-safety benefit.Twhose legitimate value isnullis neverdataReadytoday;safeDatakeeps that semantic and documents it.Verification
flutter test: 101 passeddart analyze lib test: no new issuesCloses #1118
🤖 Generated with Claude Code