问题
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