0

I have a 3 step form, For each step I am pushing a new page by passing the Bloc provider wrapped in MaterialPageRoute using Navigator so the same bloc can be accessed on those pages like this:

Navigator.of(context).push(MaterialPageRoute<TeacherTemperature>(
 builder: (_) => BlocProvider.value(value: BlocProvider.of<TeacherattendanceclassBloc>(context),
 child: TeacherTemperature()))
);

Now on the last step, when the form is completed I am doing popUntil to go back to step 1 and update the state:

Navigator.popUntil(context, ModalRoute.withName("teacherAttendanceClassList"));
BlocProvider.of<TeacherattendanceclassBloc>(context)
.add(StudentsCheckedInCompleted(widget.studentList!.length));

This successfully goes back to step 1 page and also I am able to call the event StudentsCheckedInCompleted event and the bloc is processing the state change as well.

But The step one page is not re-building for some reason? (I have tried to but the condition under the BlocBuilder as well)

This is the step one page, where I'm listening for the state in the BlocListener like this:


BlocListener<TeacherattendanceclassBloc, TeacherattendanceclassState>(
  listener: (context, state) {
      print(state);
      if(state is StudentSelectionUpdated){
          childrenSelectedList = state.studentsSelectedList;
       }

      if(state is StudentsCheckedInSuccessfull){ ----> this is not being triggered on the page
          print('StudentsCheckedInSuccessfully is triggered on the teacher attendance page');

      }
},

Am I missing somethig?

Manas
  • 3,060
  • 4
  • 27
  • 55

1 Answers1

0

This issue might be caused by State equatibility check, which means:

Assume this is your state;

class MyState extends Equatable {
    final String myVariable1;
    final int myVariable2;

    MyState({this.myVariable, this.myVariable2});

    @override
    List<Object> get props => [myVariable, myVariable2];
}

on the bottom, as you see, there is props which helps bloc to decide if state is changed or altered, and if that prop say "i am changed" (by changing any content of it), bloc rebuilds the widget. But if your state is not altered/changed as intended or you forgot to add proper props that will later say to bloc that you edited your state, your widget will not be rebuilt.

Maybe you can can add more details in code to understand the root cause. (Can you please share your bloc, events and your state objects)