Skip to content

fix(hydrated_bloc)!: HydratedCubit storage override should be a named parameter #4537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 16, 2025

Conversation

felangel
Copy link
Owner

Status

READY

Breaking Changes

YES

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@felangel felangel self-assigned this Jun 11, 2025
@felangel felangel added breaking change Enhancement candidate would introduce a breaking change pkg:hydrated_bloc This issue is related to the hydrated_bloc package labels Jun 11, 2025
Copy link
Contributor

@tmaihoff tmaihoff left a comment

Choose a reason for hiding this comment

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

thanks for fixing! lgtm

@felangel
Copy link
Owner Author

thanks for fixing! lgtm

Thanks for catching this! I'm planning to first land #4390 and do a minor bump and then will land this as part of a major version bump.

Copy link

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2e57fd8) to head (c8550ec).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #4537   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           58        58           
  Lines         1733      1731    -2     
=========================================
- Hits          1733      1731    -2     
Flag Coverage Δ
hydrated_bloc 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@felangel felangel merged commit f4c619e into master Jul 16, 2025
13 checks passed
@felangel felangel deleted the fix/hydrated-cubit-storage-override-should-be-named branch July 16, 2025 03:27
@gautam-ailoitte
Copy link

@felangel hi just a small question, don't if it's the right place to ask, how does the hydrated cubit storage works?

Suppose i have two different instance of the cubit so they both will have different storage , so how does it get's it's data upon restarts? when app kills and resumes, we are creating new instances of everything right?

this might sound like a silly question

@felangel
Copy link
Owner Author

@felangel hi just a small question, don't if it's the right place to ask, how does the hydrated cubit storage works?

Suppose i have two different instance of the cubit so they both will have different storage , so how does it get's it's data upon restarts? when app kills and resumes, we are creating new instances of everything right?

this might sound like a silly question

By default all instances use the same storage that you’ve initialized before calling runApp. You can however also override the storage on an instance by instance basis if you need.

@gautam-ailoitte
Copy link

gautam-ailoitte commented Jul 16, 2025

@felangel i'm using get_it and registered my cubit as a factory. using it in two different screens Provided to them at Screen Level. i have a _count = 0 variable in cubit and it's hydrated.

when i changed _count to 2, it was saving fine. but when i navigated to that another screen, a new cubit instance got created as expected only but now _count became 0 again.

it should’ve loaded 2 from storage via fromJson, right? i was assiging in the fromJson also, since storage is shared. to fix this, i made the cubit global instead of per screen.

what i was doing wrong here?

@felangel
Copy link
Owner Author

@felangel i'm using get_it and registered my cubit as a factory. using it in two different screens Provided to them at Screen Level. i have a _count = 0 variable in cubit and it's hydrated.

when i changed _count to 2, it was saving fine. but when i navigated to that another screen, a new cubit instance got created as expected only but now _count became 0 again.

it should’ve loaded 2 from storage via fromJson, right? i was assiging in the fromJson also, since storage is shared. to fix this, i made the cubit global instead of per screen.

what i was doing wrong here?

Are you sure the new instance was actually created after you navigated to the new screen? If you're having trouble I'm happy to take a look at a minimal reproduction sample 👍

@gautam-ailoitte
Copy link

I tried re - creating it , but in the minimal version it's working as expected all the cubits are properly getting iniatlised with the value, even if the instances are different, maybe something else was conflicting as it was a very big codebase and shared.

Thank you for this.

i also have a different doubt, in isolates, i wanted to trigger native method when i receive a firebase push notification,,

in foreground it's working fine i am able to interact with the native channels...

but in background or when the app is in killed mode, when the firebase notification is coming and if i am trying to access this method it's throwing unimplemented error, this method channel code in dart is in a service class which i am calling the firebase _onbackground message received handler.

so how can we achieve this? to trigger any piece of code when our app is in complete kill mode, also interactivity with native channels

felangel added a commit that referenced this pull request Jul 17, 2025
felangel added a commit that referenced this pull request Jul 17, 2025
felangel added a commit that referenced this pull request Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Enhancement candidate would introduce a breaking change pkg:hydrated_bloc This issue is related to the hydrated_bloc package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants