why am i getting the error? I couldn't find the reason. I'll be happy if you can help me.
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.
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
this happens when
- You have two classes with the same name
- 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>
- I will update it with more.
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.
Apart from other solutions also check if you have given type of bloc
class NewsBloc extends Bloc<NewsEvent, NewsState>
if you haven't given <NewsEvent, NewsState> it will give same error.
© 2022 - 2024 — McMap. All rights reserved.