Through the API I retrieve data of an object - including its url. I show on one screen an image with url (Image.Network()). Now, after clicking on this image on the list, I want to move to a single image view - how do I pass the image, not the url, to a new view so that the application doesn't have to download it from the url again?
In Flutter - How to pass the image downloaded from the url
2.3k Views Asked by Captivity At
2
There are 2 best solutions below
0

My code:
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (_) {
return DetailScreen(url: users[index].url);
}));
},
[...]
class DetailScreen extends StatelessWidget {
final String url;
DetailScreen({Key key, @required this.url})
: assert(url != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
child: Center(
child: PhotoView(
imageProvider: NetworkImage(url),
)
),
onTap: () {
Navigator.pop(context);
},
),
);
}
}
you can pass the image to Other Class like this
and in Other class receive the image like