gpt4 book ai didi

flutter - Flutter Dart将字符串从另一个列表转换为列表

转载 作者:行者123 更新时间:2023-12-03 04:43:20 27 4
gpt4 key购买 nike

从一个api中,我获得了带有封面艺术ID的专辑列表,然后将其列表添加到一个函数中,以从api中获取封面艺术的URL。我的问题是我试图将URL变成列表,但出现错误:“类型字符串不是列表的子类型”。如果我不尝试将其转换为列表,则可以使用URL,但我无法访问各个URL,因此可以将其显示在网格列表中。当我尝试对其进行索引时,它返回的是单个字母而不是单个URL。

class _RecentlyAddedAlbumsState extends State<RecentlyAddedAlbums> {
Future<List<Album>> albums;
List<String> coverARTLIST;
@override
Widget build(BuildContext context) {
return Scaffold(
/* backgroundColor: Colors.black, */
body: Container(
child: FutureBuilder(
future: fetchRecentlyAddedAlbums(),
builder: (context, AsyncSnapshot<List<Album>> data) {
switch (data.connectionState) {
case ConnectionState.none:
return Text(
"none",
style: TextStyle(color: Colors.black),
);
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.black),
));
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (data.hasData) {
List<Album> albums = data.data;
return ListView.builder(
itemCount: albums.length,
itemBuilder: (context, index) {
return FutureBuilder(
future: recentAlbumArt(albums[index].coverArt),
builder: (context, AsyncSnapshot cover) {
switch (cover.connectionState) {
case ConnectionState.none:
return Text(
"none",
style: TextStyle(color: Colors.black),
);
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.black),
));
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (cover.hasData) {
List<String> coverARTLIST = cover.data;
print(coverARTLIST);
return GridView.count(
scrollDirection: Axis.vertical,
crossAxisCount: 2,
shrinkWrap: true,
padding: const EdgeInsets.all(5),
crossAxisSpacing: 10,
children: <Widget>[Text("TEST")],
);
}
}
});
},
);
}
}
}),
),
);
}
}
封面功能:
Future recentAlbumArt(String coverArtID) async {
try {
var salt = randomToken(6);
var token = makeToken("$password", "$salt");
var uRL =
"$server/rest/getCoverArt/?u=$username&t=$token&s=$salt&v=$tapeOutVerison&c=$client$format&id=$coverArtID";
return uRL.toString();
} catch (e) {
print(e);
}
}

最佳答案

List<String> coverARTLIST = cover.data;这行是您出错​​的原因。您正在尝试将字符串分配给字符串列表。
试试这个

List<String> coverARTLIST=[];
coverARTLIST.add(cover.data);
print(coverARTLIST[0]);

关于flutter - Flutter Dart将字符串从另一个列表转换为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62743630/

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