I’ve been learning flutter for 2 months. I’m trying to develop a wallpaper app. I created a model and a function. But right now I can only download 1 wallpaper. How can I make this a list? I get this error when I make a list.
This is url.
String url =
'https://images.hdqwalls.com/download/the-witcher-season-2-2022-5k-u1-1080x1920.jpg';
the list i want to use
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',
];
and function
void saveimage() async {
await GallerySaver.saveImage(url, albumName: album_name);
}
and clicking this button provides download
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: () {},
),
),
);
},
);
}
The packages I use are
- gallery_saver: ^2.3.2
- async_wallpaper: ^2.0.1
I want to use it in 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),
2
Answers
Above code will resolve your error
Let consider you want to download image when you click on the card then code will be like as following.