Closed chirastefan closed 1 year ago
This package uses toJson
because that is what jsonEncode expects.
But yes, you can provide your own encoder when initialising remote devtools. Something like:
final remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000',
stateEncoder: (dynamic state) => state.toMap(),
);
and it doesn't seem to work
Sorry, I'm not familiar with dart mappables package so I think I gave you the wrong code snippet.
State Encoder needs to return a JSON sting. The default implementation is to use Dart's built in jsonEncode
, which tries to use a toJson
method on any objects it needs to encode.
As you are overriding the state encoder, you need to return a string. This actually sounds like you need to use Dart Mappables' toJson method:
final remoteDevtools = RemoteDevToolsMiddleware('192.168.1.52:8000',
stateEncoder: (dynamic state) => state.toJson(),
);
yes, but I don't think that's the issue I have with this. I'm not sure that stateEncoder
is the solution for me.
Before I used json_serializable
for which I had to create toJson
and fromJson
methods that point to the generated methods from the generated file and those functions return a Map<String, dynamic>.
This library dart_mappable
generates toJson
(returns String) and toMap
(returns Map<String, dynamic>) - this is the method I need because I want to see the state obj not a long string in the dev tools.
Is there a way to tell redux_dev_tools to look for toMap
instead of toJson
or any other solution for this issue?
@MichaelMarner
Is there a way to replace or rename this method? Context: I'm using https://pub.dev/packages/dart_mappable which generates
toJson
(returnsString
) andtoMap
(returnsMap<String,dynamic>
) on a decorated class. What I need from that class istoMap
which is whatdart-redux-remote-devtools
expectstoJson
to return;