【问题标题】:This function has a return type of 'Widget', but doesn't end with a return statement此函数的返回类型为“Widget”,但不以 return 语句结束
【发布时间】:2019-09-01 15:28:21
【问题描述】:

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

    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),
          );
        },
      );
    }   
  },
);
}

这是我的代码,我在 builder 所在的标题中收到警告。

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

【问题讨论】:

    标签: flutter dart flutter-layout


    【解决方案1】:

    您需要从 build() 方法中返回小部件,但您错过了一个案例。

    Widget _buildBody() {
      return BlocBuilder(
        bloc: _lessonsBloc,
        builder: (BuildContext context, LessonsState state) { 
          if (state is LessonsLoading) {
            return Widget1();
          } else if (state is LessonsLoaded) {
            return Widget2();
          }
    
          return CircularProgressIndicator(); // You missed this return statement. 
        },
      );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-06-16
      • 2019-05-09
      • 2019-06-19
      相关资源
      最近更新 更多