我是一名新的flutter程序员,我正在尝试构建一个在线医疗应用程序,其中包含三个选项卡部分:
在新闻部分,我试图通过youtube频道播放内容丰富的视频,为此,我参考了https://www.youtube.com/watch?v=feQhHStBVLE。
因此,我在列表类型的小部件内使用了_buildvideo()
函数,以便在新闻部分显示翔实的视频,但它正在显示
不能将元素类型功能分配给列表类型“小部件”
我在这部分卡得很厉害,如何解决这个问题?
我的源代码是
Widget build(BuildContext context) {
final _ktabpages=<Widget>[
Container(
child:ListView(
children: <Widget>[
Container(
width:430,
height:175,
child: Carousel(
animationDuration: Duration(milliseconds: 500),//animation duration controlled with this line
boxFit: BoxFit.fitWidth,
images: [
AssetImage("assets/images/Medicines.jpg"),
//AssetImage("assets/images/Doctors1.jpg"),
],
autoplay: true,
dotSize: 4.0,
dotColor: Colors.grey,
indicatorBgPadding: 4.0,
),
),
Divider(thickness: 2,),
Container(width: 430,
height: 175,
child: ListView(scrollDirection: Axis.horizontal,
children: <Widget>[//inside containers start here
Container(color: Colors.cyan[100],width: 205,
child: Column(
children: <Widget>[
//use list view with some text message to be displayed if pixel overflow occurs
//add expanded or the widgets don't fill up space during screen rotation
Expanded(child: Image.asset('assets/images/Medicines.jpg',)),
ListTile(title: Text('E-pharm'),onTap: (){
Navigator.pushNamed(context, '/secondRoute');
},
trailing: IconButton(icon: Icon(Icons.keyboard_arrow_right),onPressed: (){
Navigator.pushNamed(context, '/secondRoute');
},),)],
),
),VerticalDivider(),
Container(color: Colors.cyan[100],width: 205,
child: Column(//use list view with some text message to be displayed if pixel overflow occurs
children: <Widget>[
Expanded(child: Image.asset('assets/images/lab.png')),
//try using divider
ListTile(title: Text('Lab'),onTap: (){
Navigator.pushNamed(context, '/labRoute');
},
trailing: IconButton(icon: Icon(Icons.keyboard_arrow_right),onPressed: (){
Navigator.pushNamed(context, '/labRoute');
},),)],
),
)
],
),
),//current working conatiner
Divider(thickness: 2),
//conatiner with three iconButtons child care, mens care and womens care
Container(
width: 430,
height: 100,
child: ListView(
scrollDirection:Axis.horizontal,
children:
<Widget>[
Container(color: Colors.cyan[100],
width: 146,
child: Center(
child: IconButton(iconSize: 100,icon: Image.asset('assets/images/BabyCare.jpg'),onPressed: (){
Navigator.pushNamed(context, '/childCareRoute');
},)),
),
VerticalDivider(),
Container(
color: Colors.cyan[100],
width: 146,
// the following code distinguishes in the fact that image is used in the icon widget instead of the actual icon
child: Center(child:IconButton(icon: Image.asset('assets/images/WomanCare.jpg'),onPressed: (){
Navigator.pushNamed(context, '/womanCareView');
},iconSize: 300,)
) ),
VerticalDivider(),
Container(
color: Colors.cyan[100],
width: 146,
// the following code distinguishes in the fact that image is used in the icon widget instead of the actual icon
child: Center(child:IconButton(icon: Image.asset('assets/images/MenCare.jpg'),onPressed: (){
Navigator.pushNamed(context, '/menCareView');
},iconSize: 100,)
) )
],
)
),
Divider(thickness: 2),
Container(
width: 430,
height: 175,
color: Colors.cyan[100],
child: Column(
children: <Widget>[
//use list view with some text message to be displayed if pixel overflow occurs
//add expanded or the widgets don't fill up space during screen rotation
Expanded(child: Image.asset('assets/images/HealthCare.png',fit: BoxFit.cover,colorBlendMode: BlendMode.clear,),flex: 4,),
ListTile(title: Text('Health Products'),onTap: (){
Navigator.pushNamed(context, '/HealthProductView');
},trailing: IconButton(icon: Icon(Icons.keyboard_arrow_right),onPressed: (){
Navigator.pushNamed(context, '/HealthProductView');
},),)],
),
),
],
)),
//second tab containing the SajiloHealth blog section
//for blogsB
//Center(child: FloatingActionButton(onPressed:(){}),),
Container(),
//news section
_buildVideo(Video video) {
GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (_) => VideoScreen(id: video.id),
),
),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20.0, vertical: 5.0),
padding: EdgeInsets.all(10.0),
height: 140.0,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(0, 1),
blurRadius: 6.0,
),
],
),
child: Row(
children: <Widget>[
Image(
width: 150.0,
image: NetworkImage(video.thumbnailUrl),
),
SizedBox(width: 10.0),
Expanded(
child: Text(
video.title,
style: TextStyle(
color: Colors.black,
fontSize: 18.0,
),
),
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: _channel != null
? NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification scrollDetails) {
if (!_isLoading &&
_channel.videos.length != int.parse(_channel.videoCount) &&
scrollDetails.metrics.pixels ==
scrollDetails.metrics.maxScrollExtent) {
_loadMoreVideos();
}
return false;
},
child: ListView.builder(
itemCount: 1 + _channel.videos.length,
itemBuilder: (BuildContext context, int index) {
if (index == 0) {
return null;
}
Video video = _channel.videos[index - 1];
return _buildVideo(video);
},
),
)
: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Theme.of(context).primaryColor, // Red
),
),
),
);
}
];
答案 0 :(得分:0)
对不起,队友无法理解您的代码,但发现代码中的某些方法希望返回小部件。通常,我会检查所有存在的构建方法。