felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.83k stars 3.4k forks source link

fix: hydrated bloc stopped persisting state after update (^9.1.3) #4038

Open devopsean opened 10 months ago

devopsean commented 10 months ago

Description Hydrated bloc stopped persisting and restoring states after I updated beyond v9.1.0. When I lock in v9.1.0 in my pubspec.yaml, it works fine but when I let it run to the max possible version using "^", it does not work.

Steps To Reproduce

  1. Test state persistence using hydrated_bloc: ^9.1.0
  2. Compare with state persistence using hydrated_bloc: 9.1.0

Expected Behavior State should correctly persist.

Additional Context I get null data from persistence using hydrated_bloc: ^9.1.0

JoseGeorges8 commented 9 months ago

+1, My app seems to persist with 9.1.2 but not with 9.1.3

felangel commented 9 months ago

Sorry for the delay! I'll investigate and try to get a fix in by the end of the week, thanks!

felangel commented 9 months ago

@JoseGeorges8 @devopsean I tried to reproduce and was unable. Are either of you able to provide a link to a minimal reproduction sample with detailed steps to reproduce the error (e.g. what platform you're running on what host machine you're using, what version of flutter/dart etc)? Thanks!

Akshaymain commented 9 months ago

@felangel Steps to reproduce the error:-

  1. Use hydrated_bloc: 9.1.2
  2. Hold isLoggedIn flag in a bloc which uses HydratedMixin to store the data.
  3. Refer isLoggedIn flag whenever user access the application and route him to home-screen if it is true or login-screen if it is false.
  4. Now update hydrated_bloc version to 9.1.3 and then check. In 9.1.2 it works as expected but in 9.1.3 it routes user to login-screen all the time.

Platform: Web, Android and iOS.

Mac OS: 14.2.1 (23C71)

VS code: 1.85.2 (Universal)

Flutter and Dart version: Flutter 3.10.5 • channel stable Dart 3.0.5 • DevTools 2.23.1

devopsean commented 9 months ago

@JoseGeorges8 @devopsean I tried to reproduce and was unable. Are either of you able to provide a link to a minimal reproduction sample with detailed steps to reproduce the error (e.g. what platform you're running on what host machine you're using, what version of flutter/dart etc)? Thanks!

Flutter 3.16.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision db7ef5bf9f (10 weeks ago) • 2023-11-15 11:25:44 -0800 Engine • revision 74d16627b9 Tools • Dart 3.2.0 • DevTools 2.28.2

Mac OS: 13.5.1 (22G90)

Android Studio Giraffe | 2022.3.1 Patch 2

felangel commented 9 months ago

Thanks, I'll try to reproduce with the Flutter/Dart versions you both provided and get back to you.

Akshay-Niveus commented 6 months ago

@felangel Any update on this?

felangel commented 6 months ago

@Akshay-Niveus i'd really appreciate any reproduction steps as so far I've been unable to reproduce the issue, thanks!

vincent-hoodoo commented 5 months ago

@felangel I was able to reproduce it. It affects HydratedMixin.

It's not exactly a "bug", but rather a breaking change introduced with https://github.com/felangel/bloc/commit/e2407caf46dd217535816889ea0e6791fdc4ab3c .

Before this commit landed, even though the documentation said to call

hydrate();

in the constructor, the desired behavior would work without calling it (fromJson was called anyway from the state getter);

After the commit landed, fromJson is not called anymore if the user doesn't explicitly call it.

Not sure if a fix is required here? But since it is a breaking change, maybe it would be worth:

horlas08 commented 2 weeks ago

am facing the same issue after updating my flutter to Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git Framework • revision 2663184aa7 (5 weeks ago) • 2024-09-11 16:27:48 -0500 Engine • revision 36335019a8 Tools • Dart 3.5.3 • DevTools 2.37.3

with flutter_bloc: ^8.1.6 hydrated_bloc: ^9.1.5