plus_plugins
plus_plugins copied to clipboard
[Request]: make toMap() json compatible
Plugin
device_info_plus
Use case
renaming toMap()
as toJson
would improve compatibility with dart:convert
see referece at https://api.dart.dev/be/175791/dart-convert/jsonEncode.html
If toEncodable is omitted, it defaults to a function that returns the result of calling .toJson() on the unencodable object.
Proposal
rename BaseDeviceInfo method toMap() as toJson() and to all overrides across the package
after discussion in the PR
toJson
will not be implemented, but toMap
will be rendered json parsing compatible
Fixed this issue here #1132
@miquelbeltran could you please take a look at my question I see that there is a new PR, but I'm still waiting for a feedback
@iapicca sorry, I forgot that we had your PR on this, I apologize for not having followed up. [...]
no problem :)
As I though originally, I am not in favor of adding extra functionality to the plugins that should be external to the plugin, like JSON support.
what about fixing the crash that occurs using the current implementation of "toMap" using jsonEncode()
(caused by mapping an enum not as string)
in the question I asked I proposed 2 possible approaches
@miquelbeltran I think we have to option for the web plugin implementation:
a) remove
browserName
from bothtoMap
andfromMap
b) keep
browserName
in bothtoMap
andfromMap
ensuring consistency withuserAgent
data
b
is the current implementation and requires the committed changes, I'm not sure what changes you wish to be limited
Sorry @iapicca for not following up.
I don't think this feature has a place in the plugin, and I'd rather just deprecate and eventually remove the toMap method. Creating JSON mappings of the plugin classes should be something developers do on their own app code and not part of the plugin code.
I know this is not what you wanted to hear, but I won't close the issue and I'd let other maintainers take a look at this.
Sorry @iapicca for not following up.
[...] I'd rather just deprecate and eventually remove the toMap method.
I can do that
https://github.com/fluttercommunity/plus_plugins/issues/1139