So I have a future function here, to get a json file, parsed it and append it to a list. I want to return the data to another class that i have, so that when i call the function on that other class, i would get the return value from the function. How do i do that?
here is my function class1.dart
Future search(String stock) async {
print("Starting get request");
data.clear();
http.get("https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=" + stock + "&apikey=demo").then((res){
print("received response.");
final search = searchFromJson(res.body);
for(int i = 0; i < search.bestMatches.length; i++)
{
data.add(search.bestMatches[i].the1Symbol);
data.add(search.bestMatches[i].the2Name);
}
}).catchError((e) {
print("Failed to get response. " + e.toString());
});
return data;
}
here is my other function on another class class2.dart
void _infoModal(context, val) async{
List<String> data = await _vantage.search(val);
showModalBottomSheet(context: context, builder: (BuildContext bc) {
return Container(
child: Text(data[0]),
);
});
}