hiranthaR / Json-to-Dart-Model

Json to Dart Model extension can convert JSON objects into Dart data classes. It supports pure Dart class conversion, Flutter-recommended JSON serialization using annotations, Freezed support, Effective Dart:Style, and many more features. Currently, it has more than 135,000 installs.
https://marketplace.visualstudio.com/items?itemName=hirantha.json-to-dart
MIT License
93 stars 18 forks source link

[BUG] Unnecessary collection import #84

Closed Prn-Ice closed 2 years ago

Prn-Ice commented 2 years ago

Is there an existing issue for this?

Current Behavior

Each model class contains an import for collection and freezed_annotation. freezed_annotation already exports collection, so this is just a duplicate call.

Expected Behavior

import only freezed_annotation in model classes.

Steps To Reproduce

  1. Create a new dart project
  2. Create a freezed model using the plugin from the relevant text

No response

Version

3.5.7

Relevant JSON syntax

{
    "status": "success",
    "data": {
        "id": "577cf6ee-3cf4-4a55-8652-d8f5dd8d3375",
        "first_name": "Walter",
        "last_name": "Udoh",
        "middle_name": null,
        "email": "stormprince77@gmail.com",
        "username": "walter",
        "country": "NG",
        "email_verified_at": "2021-04-27T15:51:05.000Z",
        "phone_number": "+2347049974371",
        "phone_number_verified_at": "2021-04-05T10:57:57.000Z",
        "google_id": null,
        "facebook_id": null,
        "pin_set_at": "2021-07-01T21:28:44.000Z",
        "referral_code": "liiVF",
        "referred_by": "9e0aa010-860b-4286-acf6-22007c88b713",
        "last_logged_in_at": "2022-02-07T12:09:12.000Z",
        "status": null,
        "created_at": "2021-03-02T16:02:27.000Z",
        "updated_at": "2022-02-07T12:09:12.000Z",
        "currency": {
            "code": "NGN",
            "decimals": 2,
            "name": "Nigerian naira",
            "number": "566",
            "symbol": "₦"
        }
    }
}

Anything else?

No response

iamarnas commented 2 years ago

@Prn-Ice Thanks for this. I will fix it as soon as possible.

iamarnas commented 2 years ago

@Prn-Ice :wave: I have tested it and I have not encountered any problems. Json to Dart Model generator generate imports for two different packages. Example:

json_serializable

import 'package:collection/collection.dart'; // generates if equality enabled.
import 'package:json_annotation/json_annotation.dart';

freezed

import 'package:freezed_annotation/freezed_annotation.dart';

And as you know freezed has both imports for json_serializable. The problem is that I can not use freezed import for json_serializable because not everyone uses a freezed, some developers only use json_serializable or vice versa.

Prn-Ice commented 2 years ago

I see, thanks