Я использую этот пример для вызова API, но я сталкиваюсь с ошибкой, т.е.
InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
Ниже приведен код для вызова API
class RandomUserRepository implements ContactRepository {
static const _kRandomUserUrl = 'http://api.randomuser.me/?results=15';
Future<List<Contact>> fetch() async {
final response = await http.get(_kRandomUserUrl);
final jsonBody = response.body;
final statusCode = response.statusCode;
if(statusCode < 200 || statusCode >= 300 || jsonBody == null) {
throw FetchDataException("Error while getting contacts
[StatusCode:$statusCode, Error:${response.reasonPhrase}]");
}
final Map<String,dynamic> contactsContainer =
json.decode(jsonBody);//.convert(jsonBody);
final List<dynamic> contactItems = contactsContainer['results'];
print("HERE LIST ******** > $contactItems");
return contactItems.map( (contactRaw) => Contact.fromMap(contactRaw)
).toList();
}
}
, и синтаксический анализ выполняется следующим образом
Contact.fromMap(Map<String, dynamic> map) :
fullName = "${map['name']['first']} ${map['name']. ['last']}",
gender = map['gender'],
email = map['email'],
imageUrl = map['picture']['large'],
birthday = _formatter.format(DateTime.parse(map['dob']['date'])),
location = Location.fromMap(map['location']),
phones = <Phone>[
new Phone(type: 'Home', number: map['phone']),
new Phone(type: 'Mobile', number: map['cell'])
];