6

why am i getting the error? I couldn't find the reason. I'll be happy if you can help me.

error screen

You can check my issue on github

Serkan Ağca
  • 155
  • 1
  • 6
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Apr 11 '22 at 12:26

4 Answers4

6

hello i solved the problem. The problem was giving an error because there were 2 classes with the same name, so my StatefulWidget class name was the same as my block state class name :) It was fixed when I changed the name of my block state class.

enter image description here enter image description here

Serkan Ağca
  • 155
  • 1
  • 6
0

You can use same name for StatefulWidget state and use again that name in block or state please dont repeat same name that's wht that errors come

Nikhil Kadam
  • 109
  • 4
0

this happens when

  1. You have two classes with the same name
  2. You add the bloc instead of the event

ex:


class CounterBloc extends Bloc<CounterBloc, CounterState> {
  CounterBloc() : super(const InitialState()) {
    on<IncrementEvent>((event, emit) {
      emit(IncrementedCounterState());
    });
    on<IncrementEvent>((event, emit) {
      emit(DecrementedCounterState());
    });
  }
}

I should pass the Event not the bloc in the Bloc<CounterBloc,CounterState> and it should be Bloc<CounterEvent,CounterState>

  1. I will update it with more.
0

If the following primary cause for this issue :

there were 2 classes with the same name

is not the solution , or you have already fixed it and still having the problem,

Simply run the flutter clean and flutter pub get command to fix it.

Akshay Chopra
  • 1,035
  • 14
  • 10