I have a freezed class in my Flutter app. I'm serializing it to a Map and trying to send it over a port to another isolate.
Receiving this weird error:
E/flutter (23696): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument: is a regular instance reachable via <- _List len:16 (from dart:core)
E/flutter (23696): <- _Map len:7 (from dart:collection)
E/flutter (23696): <- _List len:32 (from dart:core)
E/flutter (23696): <- _Map len:12 (from dart:collection)
E/flutter (23696): <- _List len:8 (from dart:core)
E/flutter (23696): <- _Map len:3 (from dart:collection)
E/flutter (23696): <- _List len:8 (from dart:core)
E/flutter (23696): <- _Map len:2 (from dart:collection)
E/flutter (23696): : Instance of 'EqualUnmodifiableListView<bool>'
E/flutter (23696): #0 _SendPort._sendInternal (dart:isolate-patch/isolate_patch.dart:249:43)
E/flutter (23696): #1 _SendPort.send (dart:isolate-patch/isolate_patch.dart:230:5)
This error goes away when I remove a List in my class. I wonder why this is happening.
This is happening because freezed uses a weird list type (EqualUnmodifiableListView) and port is not able to send it somehow. The error message is not helping very much.
The following code helps fix the issue: