Cretezy / redux_persist

Persist Redux State
https://pub.dartlang.org/packages/redux_persist
MIT License
130 stars 41 forks source link

Error [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'AppMainState' #76

Closed abhineetchandan closed 2 years ago

abhineetchandan commented 2 years ago

I am using SpeechToText object in my store. But I omit it in JSON serializer. But it is causing an error

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'AppMainState'

[        ] E/flutter ( 4073): #0      _JsonStringifier.writeObject (dart:convert/json.dart:794:7)

[        ] E/flutter ( 4073): #1      _JsonStringStringifier.printOn (dart:convert/json.dart:983:17)

[        ] E/flutter ( 4073): #2      _JsonStringStringifier.stringify (dart:convert/json.dart:968:5)

[        ] E/flutter ( 4073): #3      JsonEncoder.convert (dart:convert/json.dart:345:30)

[        ] E/flutter ( 4073): #4      JsonCodec.encode (dart:convert/json.dart:231:45)

[        ] E/flutter ( 4073): #5      JsonSerializer.encode (package:redux_persist/src/serialization.dart:28:35)

[        ] E/flutter ( 4073): #6      Persistor.save (package:redux_persist/src/persistor.dart:154:29)

[        ] E/flutter ( 4073): #7      Persistor.createMiddleware.<anonymous closure>.<anonymous closure> (package:redux_persist/src/persistor.dart:66:57)

[        ] E/flutter ( 4073): #8      _rootRun (dart:async/zone.dart:1418:47)

[        ] E/flutter ( 4073): #9      _CustomZone.run (dart:async/zone.dart:1328:19)

[        ] E/flutter ( 4073): #10     _CustomZone.runGuarded (dart:async/zone.dart:1236:7)

[        ] E/flutter ( 4073): #11     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)

[        ] E/flutter ( 4073): #12     _rootRun (dart:async/zone.dart:1426:13)

[        ] E/flutter ( 4073): #13     _CustomZone.run (dart:async/zone.dart:1328:19)

[        ] E/flutter ( 4073): #14     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1260:23)

[        ] E/flutter ( 4073): #15     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)

[        ] E/flutter ( 4073): #16     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)

[        ] E/flutter ( 4073): #17     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)

[        ] E/flutter ( 4073): #18     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Here's the code for my serializer

AppMainState.fromJSON(dynamic json) {
    if (json == null) {
      AppMainState();
    } else {
      AppMainState(
        texts: json["texts"],
      );
    }
  }

I am not serializing the SpeechToText object but the object is present in my Redux store. Is that the reason of the problem? EDIT: It is also not able to encode a list. Thanks in advance