lesnitsky / flutter_localstorage

📦 LocalStorage for Flutter
MIT License
301 stars 60 forks source link

Error: NoSuchMethodError: 'toJson' #79

Closed moses-everette closed 2 years ago

moses-everette commented 2 years ago

I'm not sure why this magically began to appear. On setItem(key, value), the debugger blows up and tells me that 'toJson' does not exist. However, data is still written to local storage. It is really odd.

flutter doctor -v

Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1165], locale en-US) [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [√] Chrome - develop for the web [!] Android Studio (not installed) [√] VS Code (version 1.59.0) [√] Connected device (2 available)

! Doctor found issues in 1 category.

C:\Users\everettem\Documents\cmms\server>flutter doctor -v [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1165], locale en-US) • Flutter version 2.2.3 at C:\Users\everettem\Documents\flutter • Framework revision f4abaa0735 (6 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4

[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at C:\Users\everettem\AppData\Local\Android\sdk • Platform android-31, build-tools 31.0.0 • Java binary at: C:\Users\everettem\Documents\jdk-11.0.2\bin\java.exe • Java version OpenJDK Runtime Environment 18.9 (build 11.0.2+9) • All Android licenses accepted.

[√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code (version 1.59.0) • VS Code at C:\Users\everettem\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.25.0

[√] Connected device (2 available) • Chrome (web) • chrome • web-javascript • Google Chrome 92.0.4515.131 • Edge (web) • edge • web-javascript • Microsoft Edge 92.0.902.67

lesnitsky commented 2 years ago

Could you please provide a minimal reproducible example?

moses-everette commented 2 years ago

So I believe this issue isn't the library itself. I think the issue lies within some problem with the flutter toolset itself. My issue boiled to some failed state change after a network request. The logic follows as is:

Not sure adding code helps this situation out at all, as I'm not running into nulls (that I'm aware of). And everything I expect to be written to local storage is there. I think it had to do with a race condition between two futures (currently my auth is two-stage. I might just reduce to single-stage authentication). Embedding the second callback into the first appears to have fixed the issue. So maybe this is my fault, but might be worth reporting here incase there is something that helps you!

moses-everette commented 2 years ago

Actually, you can close this. This is because I mistakenly did not wait for the storage to be ready. Newb move. Newb. Move.