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 17 forks source link

The annotation 'JsonKey' can only be used on fields or getters dart (invalid_annotation_target) #85

Closed Prn-Ice closed 2 years ago

Prn-Ice commented 2 years ago

Is there an existing issue for this?

Current Behavior

Models created that contain a JsonKey produce the following lint warning.

The annotation 'JsonKey' can only be used on fields or getters dart(invalid_annotation_target)

This is fixed by adding

// ignore_for_file: invalid_annotation_target

To the top of the file.

Expected Behavior

No lint warning

Steps To Reproduce

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

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 Hey there šŸ‘‹

This is known issue and it come not from the extension side. You can read here how to fix it šŸ‘‰ fix.

Prn-Ice commented 2 years ago

I see thanks