plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[Request]: make toMap() json compatible

Open iapicca opened this issue 2 years ago • 1 comments

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

iapicca avatar Jul 07 '22 11:07 iapicca

after discussion in the PR toJson will not be implemented, but toMap will be rendered json parsing compatible

iapicca avatar Jul 19 '22 06:07 iapicca

Fixed this issue here #1132

Yczar avatar Oct 02 '22 00:10 Yczar

@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 avatar Oct 02 '22 15:10 iapicca

@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 both toMap and fromMap

b) keep browserName in both toMap and fromMap ensuring consistency with userAgent data

b is the current implementation and requires the committed changes, I'm not sure what changes you wish to be limited

iapicca avatar Oct 02 '22 15:10 iapicca

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.

miquelbeltran avatar Oct 02 '22 15:10 miquelbeltran

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

iapicca avatar Oct 02 '22 16:10 iapicca