gpt4 book ai didi

flutter - 在Flutter中List 不是List 的子类型

转载 作者:行者123 更新时间:2023-12-03 04:54:50 24 4
gpt4 key购买 nike

我在列窗口小部件中调用了AttachmentWidget(snapshot.data)方法,因此可以从API动态获取数据。接收到此数据后,根据存储在路径列表中的ext(例如图像扩展名),我将其存储为图像路径。在这种情况下,如果我获得5张图像,我想将5个路径列表路径到Photogrid imageUrls: imgpathList,为此,我收到了一个错误

error message


List<dynamic>  is not a subtype of List<String>

那么,如何将List转换为List或有什么方法呢?谢谢

Code here


Widget AttachmentWidget(List<Attachment> attachmentmodel)
{
int listsize=attachmentmodel.length;

var imgpathList = new List();
var videopathList = new List();
var audiopathList = new List();


int images=0;
int videos=0;
int audio=0;
int others=0;

Set <String> ImageExt = {'jpg','png','jpeg','tiff'};
Set <String> VideoExt = {'mp4','mpeg4','wmp'};
Set <String> AudioExt={'mpga'};

for(int i=0;i<=listsize-1;i++)
{
String ext=attachmentmodel[i].ext;
String path=attachmentmodel[i].path;

if(ImageExt.contains(ext))
{
images=images+1;
imgpathList.add(path);
}
else if(VideoExt.contains(ext))
{
videos=videos+1;
videopathList.add(path);
}
else if(AudioExt.contains(ext))
{
audio=audio+1;
audiopathList.add(path);
}
else
{
others=others+1;
}
}


if(listsize==0)
{
return Container();
}
else if(listsize==1&&images==1)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Image.network(
imgpathList[0]
)
);
}
else if(listsize==1&&videos==1)
{
return Text('video');
}
else if(listsize==1&&audio==1)
{
return Text('audio');
}
//////////////////////////////list size 2
else if(listsize==2&&images==2)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
Image.network(
imgpathList[0]
),
Image.network(
imgpathList[1]
),
],
)
);
}
else if(listsize==2&&videos==2)
{
return Text('2 videos');
}
else if(listsize==2&&audio==2)
{
return Text('2 audios');
}
else if(listsize==2&&images==1&&videos==1)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[

Image.network(
imgpathList[0]
),

Text('video2')

]
)
);
}
else if(listsize==2&&images==1&&audio==1)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[

Image.network(
imgpathList[0]
),

Text('audio')

]
)
);
}
else if(listsize==2&&videos==1&&audio==1)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[

Text('video'),

Text('audio')

]
)
);
}
else if(listsize==3&&images==3)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
Container(
height: 200,
child: Image.network(
imgpathList[0]
),
),
Container(
height: 200,
child: Column(
children: <Widget>[
Container(
height: 100,
child: Image.network(
imgpathList[1]
),
),
Container(
height: 100,
child: Image.network(
imgpathList[2]
),
),
],
),
),
]
)
);
}
else if(listsize==3&&videos==3)
{
return Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
Container(
height: 200,
child: Text('1')
),
Container(
height: 200,
child: Column(
children: <Widget>[
Container(
height: 100,
child: Text('2')
),
Container(
height: 100,
child: Text('3')
),
],
),
),
]
)
);
}
else if(listsize==4&&images==4)
{
return Container(
height: 300,
width: MediaQuery.of(context).size.width,
child: Row(
children: <Widget>[
Container(
height: 300,
child: Column(
children: <Widget>[
Container(
height:150,
width: 150,
child: Image.network(
imgpathList[0]
),
),
Container(
height:150,
width: 150,
child: Image.network(
imgpathList[1]
),
),
],
)
),
Container(
height: 300,
child: Column(
children: <Widget>[
Container(
height:150,
width: 150,
child: Image.network(
imgpathList[2]
),
),
Container(
height:150,
width: 150,
child: Image.network(
imgpathList[3]
),
),
],
)
),
]
)
);
}

else if(listsize>=5&&images>=5)
{
return PhotoGrid(
imageUrls: imgpathList,
onImageClicked: (i) => print('Image $i was clicked!'),
onExpandClicked: () => print('Expand Image was clicked'),
maxImages: 4,
);

}
else
{
return Text('list size $listsize \n images $images \n videos $videos \n audios $audio');
}

}

最佳答案

发生这种情况是因为您没有提供特定类型的list.t。

尝试按照以下原因声明列表。

List<String> imgpathList = new List();
List<String> videopathList = new List();
List<String> audiopathList = new List();

关于flutter - 在Flutter中List <dynamic>不是List <String>的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60774432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com