Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This function has a return type of 'Widget', but doesn't end with a return statement

There are a few similar problems on the site but I could not make up exactly

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

This is my code and I get the warning in the header where builder is.

I would appreciate it if someone give a solution or an idea:)

like image 792
alternative4 Avatar asked Sep 01 '19 15:09

alternative4


1 Answers

You need to return widget from within the build() method and you missed a case.

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. 
    },
  );
}
like image 60
CopsOnRoad Avatar answered Oct 12 '22 21:10

CopsOnRoad