Serializing JSON inline

By looking at the dart:convert documentation,
you’ll see that you can decode the JSON by calling the
jsonDecode() function, with the JSON string as the method argument.

Unfortunately, jsonDecode() returns a Map<String, dynamic>, meaning
that you do not know the types of the values until runtime. With this approach,
you lose most of the statically typed language features: type safety,
autocompletion and most importantly, compile-time exceptions. Your code will
become instantly more error-prone.

For example, whenever you access the name or email fields, you could quickly
introduce a typo. A typo that the compiler doesn’t know about since the
JSON lives in a map structure.

Serializing JSON inside model classes

Combat the previously mentioned problems by introducing a plain model
class, called User in this example. Inside the User class, you’ll find:

A User.fromJson() constructor, for constructing a new User instance from a
map structure.