【发布时间】:2022-11-17 20:06:53
【问题描述】:
我已经学习 flutter 两个月了。我正在尝试开发壁纸应用程序。我创建了一个模型和一个函数。但是现在我只能下载 1 张壁纸。我怎样才能把这个列成一个清单?我在列清单时收到此错误。
这是网址。
String url =
'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg';
我要使用的列表
List<String> url = [
'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg',
'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg',
];
和功能
void saveimage() async {
await GallerySaver.saveImage(url, albumName: album_name);
}
单击此按钮提供下载
ElevatedButton DownloadButton(BuildContext context) {
return ElevatedButton(
style: ElevatedButton.styleFrom(
minimumSize: Size(40, 40),
shape: CircleBorder(),
backgroundColor: Colors.grey.shade600.withOpacity(0.1),
),
child: Icon(Icons.download, color: Colors.white.withOpacity(0.7)),
onPressed: () {
saveimage();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
duration: Duration(seconds: 2),
content: Text('Wallpaper downloaded!'),
action: SnackBarAction(
label: '',
onPressed: () {},
),
),
);
},
);
}
我使用的包是
- 画廊保护程序:^2.3.2
- async_wallpaper: ^2.0.1
我想在 gridview 中使用它
GridView.builder(
itemCount: url.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 9 / 16,
),
itemBuilder: (BuildContext context, int index) {
return Card(
child: Padding(
padding: EdgeInsets.all(1.0),
child: FullScreenWidget(
child: Stack(fit: StackFit.expand, children: [
Image.network(url, fit: BoxFit.cover),
【问题讨论】:
标签: flutter flutter-dependencies flutter-test