AsyncSnapshot <...>不是AsyncSnapshot <dynamic>的子类型,AsyncWidgetBuilder错误

时间:2019-10-23 15:18:25

标签: flutter dart

我有一个特殊的类来处理来自资源的响应(RepositoryResponse类)。

class RepositoryBuilder<T extends RepositoryResponse> extends StatefulWidget {
  final Future<T> future;
  final AsyncWidgetBuilder<T> builder;

  const RepositoryBuilder({this.future, this.builder});

  @override
  _RepositoryBuilderState createState() => _RepositoryBuilderState<T>();
}

class _RepositoryBuilderState<T extends RepositoryResponse> extends State<RepositoryBuilder> {
  Future<T> future;

  @override
  void initState() {
    future = widget.future;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder<T>(future: future, builder: widget.builder);
  }
}

这是我的应用程序中的一个屏幕的一部分:

RepositoryBuilder<RepositoryResponse<Set<Invoice>>>(
          future: orderRepository.fetchInvoices(),
          builder: (context, snapshot) {
            if(snapshot.hasData){
              return snapshot.data.apiData.isEmpty
                ? SomeWidget()
                : AnotherWidget();
            }
          },
        )

所以,到今天结束,这是错误,对我来说这没有意义:

  

在构建RepositoryBuilder<RepositoryResponse<Set<Invoice>>>(dirty, state: _RepositoryBuilderState<RepositoryResponse<Set<Invoice>>>#e23da)时引发了以下断言:   类型“ (BuildContext, AsyncSnapshot<RepositoryResponse<Set<Invoice>>>) => Widget”不是类型“ (BuildContext, AsyncSnapshot<RepositoryResponse<dynamic>>) => Widget”的子类型

那么,Object<A>在地球上怎么不能成为Object<dynamic>的子类型?

0 个答案:

没有答案