Flutter blocTest 泛型函数缺少类型参数 'blocTest<B extends BlocBase<State>, State>'

Flutter blocTest Missing type arguments for generic function 'blocTest<B extends BlocBase<State>, State>'

在遵循 bloc 测试 documentation 时,我创建了以下内容 blocTest;

blocTest('should do something',
    build: () => SignInBloc(signIn: mockSignIn),
    act: (bloc) => bloc.add(const OnEmailChanged(email: 'test')));

但是我得到了智能感知错误;

Missing type arguments for generic function 'blocTest<B extends BlocBase<State>, State>'.

add中提供的(bloc)类型为Object?

要解决此问题,您必须告诉 blocTest 期望的类型。

blocTest<SignInBloc, SignInState>('should do something',
    build: () => SignInBloc(signIn: mockSignIn),
    act: (bloc) => bloc.add(const OnEmailChanged(email: 'test')));
  });