This is the response from request.
var response = [{"id":4731},{"id":4566},{"id":4336},{"id":4333},{"id":4172},{"id":4170},{"id":4168},{"id":4166},{"id":4163},{"id":4161}];
How to extract ids and store in List of int using flutter. I have try this code but not working.
Future<List<int>> fetchTopIds() async{
final response = await client.get('$_baseUrl/posts?fields=id');
final ids = json.decode(response.body);
return ids.cast<int>();
}
This should do what you want:
var intIds = ids.map<int>((m) => m['id'] as int).toList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With