I have a dynamic data from json, then I want to change it to a list variable, so i can be called that variable by the getSuggestions function. Here is the code :
static List<String> people = new List<String>();
void getUsers() async {
try {
final response =
await http.get("https://jsonplaceholder.typicode.com/users");
var resbody = json.decode(response.body);
var data = json.encode(resbody[0]);
if (response.statusCode == 200) {
setState(() {
people = data;
});
} else {
print("Error getting users.");
}
} catch (e) {
print("Error getting users.");
}
}
static List<String> getSuggestions(String query) {
List<String> matches = List();
matches.addAll(people);
matches.retainWhere((s) => s.toLowerCase().contains(query.toLowerCase()));
return matches;
}```