'_Type'不是'Widget'类型的子类型

Sam*_*RAK 1 widget flutter

我在NoContentPage中将红色屏幕“ _Type”不是“ Widget”类型的子类型异常记录下来,写下了完整的组件代码并将其放置在StatefulWidget中。这段代码有什么问题。我认为这是一个非常普遍的例外。

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,
                  )))
        ],
      ),
    ));
  }
}
Run Code Online (Sandbox Code Playgroud)

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,
                                ),
                              ]));
                        }),
          )
Run Code Online (Sandbox Code Playgroud)

Rém*_*let 12

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

return Foo;
Run Code Online (Sandbox Code Playgroud)

return Foo();
Run Code Online (Sandbox Code Playgroud)

  • 他们什么时候会发明一种错误消息为“你忘记了括号”的语言 (2认同)