'How to get data from Future<dynamic> function Flutter
I'm getting data with this function:
Future<dynamic> getItem(String endpoint, List<String> pathParams) async {
final uri = buildUri(endpoint, pathParams, {});
final response = await http.get(uri, headers: {
'Authorization': 'Bearer $_ACCESS_TOKEN',
'Content-Type': 'application/json'
});
if (response.statusCode == _UNAUTHORIZED) {
return _refresh(
() => getItem(endpoint, pathParams), () => _redirectToLogin());
}
return response.body;
}
When I try to use the data like this:
List user = [];
void getItem() async {
List tmp = await ac.getItem("/v1/users/:0", [idProfile]);
if (mounted) {
setState(() {
user = tmp;
});
}
}
It sais me: it's not a subtype... I've tried with List, List, List, Map, Map<String, dynamic>, and nothing works. What type should I use?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
