0

I created bloc with "on" handler where I request topics from API. I can control loading and error. I add the second "on" handler in bloc where I request top selected topic, and I want to work with the same bloc with topics to save this top selected topic near all topics: List<Topic> topics = [], Topic topSelected = TopSelected(...) something like that

I created one more method in my state to upload this top selected topic and it was loaded well, but when I render data in my widget via state.when I face with error because I need to implement all state methods in the widget (render topSelected and topic) but I need only topSelected in my widget

[WIDGET(https://i.stack.imgur.com/6FKuy.png)] [STATE(https://i.stack.imgur.com/CF9wx.png)] [EVENTS(https://i.stack.imgur.com/DkcGv.png)] [BLOC(https://i.stack.imgur.com/pkR7l.png)

I tried to create on more method in my state but I faced with error in the widget. May be I can mark this methods as non required or a kind of it?

1 Answers1

1

Maybe I'm too late, but it will be helpful to others. You can use maybeWhen, to use only specific conditions with default value in orElse parameter:

BlocBuilder<AuthCubit, QuizzesState>(
   builder: (context, state) {
      return state.maybeWhen(
         loading: () => Text('Loading'),
         orElse: () => Text('orElse'),
       );
    },
),