简体   繁体   中英

( Flutter Bloc ) doesn't conform to the bound 'StateStreamable<state>' of the type parameter 'B'

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

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.

在此处输入图像描述 在此处输入图像描述

您可以对 StatefulWidget 状态使用相同的名称,并在块或状态中再次使用该名称请不要重复相同的名称,这就是错误来的原因

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM