pubspec.yaml

dependencies

# Your other regular dependencies here

json_annotation

<latest_version>

dev_dependencies

# Your other dev_dependencies here

build_runner

<latest_version>

json_serializable

<latest_version>

Run flutter pub get inside your project root folder
(or click Packages get in your editor)
to make these new dependencies available in your project.

Creating model classes the json_serializable way

The following shows how to convert the User class to a
json_serializable class. For the sake of simplicity,
this code uses the simplified JSON model
from the previous samples.

user.dart

With this setup, the source code generator generates code for encoding
and decoding the name and email fields from JSON.