flutter常见问题

  1. 新版 flutter,ancestorWidgetOfExactType 方法过时
    老方法:
1
2
3
4
5
static T of<T extends BlocBase>(BuildContext context) {
final type = _typeOf<BlocProvider<T>>();
BlocProvider<T> provider = context.ancestorWidgetOfExactType(type);
return provider.bloc;
}

新方法:

1
2
3
4
static T of<T extends BlocBase>(BuildContext context) {
BlocProvider<T> provider = context.findAncestorWidgetOfExactType<BlocProvider<T>>();
return provider.bloc;
}