I am fairly new to fluter, I've looked everywhere and found no solution to my error. I want to return the result print from an api call, but I am unable to. I end up getting "Instance of 'Future" instead of printing the List
The error which I keep getting
Instance of 'Future<List>'
My code
class _SuperVisorSheetState extends State<SuperVisorSheet> {
Future <List> clusters;
Future<List> getClusters() async{
var response = await Dio().get('http://192.168.100.3:8080/api/v1/clustertable');
return response.data;
}
@override
void initState() {
// TODO: implement initState
clusters = getClusters();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff392850),
title: Text("Supervisor "),
),
body: Container(
padding: EdgeInsets.all(10),
child: FutureBuilder<List>(
future: clusters,
builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
if(snapshot.hasData){
print(clusters);
return Text("Hello");
}
return null;
},
)
>'`