Flutter 未调用Dart方法

Flutter 未调用Dart方法,flutter,dart,bloc,Flutter,Dart,Bloc,我在带有BLoC的dart/flatter项目中有以下代码 抽象类BasePage扩展了无状态小部件{ 小工具得到身体; const BasePage({@required Key}):super(Key:Key); Bloc创建(构建上下文){ final dao=Provider.of(上下文,listen:false); 返回LessonListBloc(dao)…添加(LoadListEvent()); } @凌驾 小部件构建(构建上下文){ final blocs=createBloc

我在带有BLoC的dart/flatter项目中有以下代码

抽象类BasePage扩展了无状态小部件{
小工具得到身体;
const BasePage({@required Key}):super(Key:Key);
Bloc创建(构建上下文){
final dao=Provider.of(上下文,listen:false);
返回LessonListBloc(dao)…添加(LoadListEvent());
}
@凌驾
小部件构建(构建上下文){
final blocs=createBlocs(上下文);
返回BlocProvider(
懒惰:错,
创建:(上下文){
返回创建(上下文);
},
子对象:材质(子对象:主体),
);
}
}
现在,当我想将create的函数返回类型更改为
Bloc
时,订户小部件(即侦听LessonListBloc中
yield
加载的LessonsListLoaded)不会传递到
主体
小部件:

Bloc创建(BuildContext){
final dao=Provider.of(上下文,listen:false);
返回LessonListBloc(dao)…添加(LoadListEvent());
}

您依赖LessonListBloc

但是BlocBuilder不能得到它

在创建函数LessonListBloc->Bloc中,您缩小了类型的范围

这会奏效的

create(...)
LessonListBloc create(...)
这不会

Bloc create(...)
用类型重写代码,analisator将弹出类型不匹配错误

BlocProvider<LessonListBloc>(...
BlocProvider(。。。