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?
            Asked
            
        
        
            Active
            
        
            Viewed 2,230 times
        
    2
            
            
        - 
                    1Can you please show some code of what you have right now? It will be easier to provide an answer – Stefano Saitta Apr 08 '20 at 10:45
- 
                    1Either you can pass the image as a parameter, or use `https://pub.dev/packages/cached_network_image` it will cache the image locally so that it won't download next time. – Midhun MP Apr 08 '20 at 10:53
- 
                    my code is below – Captivity Apr 08 '20 at 15:10
2 Answers
1
            you can pass the image to Other Class like this
Navigator.push(
          context, MaterialPageRoute(builder: (context) => OtherClass(data: image)));
and in Other class receive the image like
   var data;
   OtherClass({Key key, @required this.data}) : super(key: key);
 
    
    
        Sanwal Ijaz
        
- 154
- 1
- 11
- 
                    And how to get the date: image if I only have Object.url (image address) – Captivity Apr 08 '20 at 14:57
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);
                },
            ),
        );
    }
}
 
    
    
        Captivity
        
- 279
- 5
- 21