我有一个图形 View 我的应用程序,只要我的函数起作用,它也会重新构建
如何控制我的UI

var response = await getdashboarddata(tokenkey);
setState(() {

});

最佳答案

使用FutureBuilder

 Widget projectWidget() {
  return FutureBuilder(
    builder: (context, projectSnap) {
      if (projectSnap.connectionState == ConnectionState.none &&
          projectSnap.hasData == null) {
        //print('project snapshot data is: ${projectSnap.data}');
        return Container();
      }
      return ListView.builder(
        itemCount: projectSnap.data.length,
        itemBuilder: (context, index) {
          ProjectModel project = projectSnap.data[index];
          return Column(
            children: <Widget>[
              // Widget to display the list of project
            ],
          );
        },
      );
    },
    future: getdashboarddata(tokenkey),
  );
}
@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('ProjectList'),
    ),
    body: projectWidget(),
  );
}

08-18 17:49