'_Type' is not a subtype of type 'Widget'

柔情痞子 提交于 2020-05-13 14:40:10

问题


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,
                  )))
        ],
      ),
    ));
  }
}

called

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,
                                ),
                              ]));
                        }),
          )

回答1:


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

return Foo;

vs

return Foo();


来源:https://stackoverflow.com/questions/54943770/type-is-not-a-subtype-of-type-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!