fromMap function
Creates a new instance of type
and maps the data of dataObject
into it.
example:
// Simple type conversion
Person person = fromMap({"id": 1, "name": "John Doe"}, Person);
// List conversion
List<Person> persons = fromMap([{"id": 1, "name": "John Doe"}], [() => List<Person>, Person]);
// Map conversion
Map<String, Person> personsMap = fromMap({"person1": {"id": 1, "name": "John Doe"}}, [() => Map<String, Person>(), [String, Person]]);
// Generic conversion
Page<Person> page = fromMap({
"number": 1,
"size": 3,
"total": 100,
"items": [
{"id": 1, "name": "person1"},
{"id": 2, "name": "person2"},
{"id": 3, "name": "person3"}
]
}, [() => Page<Person>(), {'items': [() => List<Person>(), Person]}]);
Throws NoConstructorError if type
or Classes used inside type
do not
have a constructor without or only optional arguments.
Throws IncorrectTypeTransform if json data types doesn't match.
Throws FormatException if the jsonStr
is not valid JSON text.
Implementation
dynamic fromMap(Object dataObject, /*Type | List<Type> | List<List<Type>>*/ type) {
return _convertValue(type, dataObject);
}