'_Type'不是'Widget'类型的子类型 [英] '_Type' is not a subtype of type 'Widget'

查看:236
本文介绍了'_Type'不是'Widget'类型的子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NoContentPage中,我将红屏显示为'_Type'不是'Widget'类型的子类型,我写下了完整的组件代码并将其放置到StatefulWidget中.这段代码有什么问题.我认为这是扑朔迷离中非常普遍的例外.

I took the red screen '_Type' is not a subtype of type 'Widget' exception in NoContentPage I wrote down the full component code and called place into StatefulWidget. What is wrong in this code. I think it is a very common exception in the flutter.

class NoContentPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return (new Container(
      width: 320.0,
      child: new Column(
        children: <Widget>[
          Center(
              child: Text(AppLocalizations.of(context).messageNoContent,
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 20.0,
                    fontWeight: FontWeight.w300,
                    letterSpacing: 0.3,
                  )))
        ],
      ),
    ));
  }
}

称为

body: Container(
            child: videos == null
                ? Center(child: CircularProgressIndicator())
                : videos.length == 0
                    ? NoContentPage
                    : ListView.builder(
                        itemCount: videos.length,
                        itemBuilder: (context, index) {
                          return GestureDetector(
                              onTap: () {
                                playYoutubeVideo(videos[index][Video.videoUrl]);
                              },
                              child: Column(children: [
                                new YoutubeCard(
                                  video: videos[index],
                                ),
                                new Divider(
                                  height: 0.0,
                                  color: Colors.grey,
                                ),
                              ]));
                        }),
          )

推荐答案

您的错误是您返回的是类型,而不是给定类型的实例:

Your mistake is that you returned the type instead of the instance of a given type:

return Foo;

vs

return Foo();

这篇关于'_Type'不是'Widget'类型的子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆