此函数的返回类型为“小部件”,但不以return语句结尾

时间:2019-09-01 15:28:21

标签: flutter dart flutter-layout

该网站上存在一些类似的问题,但我无法完全弥补

    Widget _buildBody(tab) {
   return BlocBuilder(
  bloc: _lessonsBloc,
  builder: (BuildContext context, LessonsState state) { //HERE 
    if (state is LessonsLoading) {
      return Center(
        child: CircularProgressIndicator(),
      );
    } else if (state is LessonsLoaded) {
          return ListView.builder(

        itemCount: state.lessons.length,
        itemBuilder: (context, index) {
          final displayedLessons = state.lessons[index];
          return ListTile(
            title: Text(displayedLessons.name),
            subtitle:Text(displayedLessons.subname),
            trailing: _buildUpdateDeleteButtons(displayedLessons),
          );
        },
      );
    }   
  },
);
}

这是我的代码,在生成器所在的标题中得到警告。

如果有人提出解决方案或想法,我将不胜感激:)

1 个答案:

答案 0 :(得分:3)

Widget _buildBody(tab) {
  return BlocBuilder(
    bloc: _lessonsBloc,
    builder: (BuildContext context, LessonsState state) { //HERE
      if (state is LessonsLoading) {
        return Center(
          child: CircularProgressIndicator(),
        );
      } else if (state is LessonsLoaded) {
        return ListView.builder(

          itemCount: state.lessons.length,
          itemBuilder: (context, index) {
            final displayedLessons = state.lessons[index];
            return ListTile(
              title: Text(displayedLessons.name),
              subtitle:Text(displayedLessons.subname),
              trailing: _buildUpdateDeleteButtons(displayedLessons),
            );
          },
        );
      }

      return Container(); // you need to return any widget from here. You could use CircularProgressIndicator() also. 
    },
  );
}