Search code examples
imageflutterdartfile-uploadflutter-layout

How to download image to gallery in flutter


I am working with school management application, here I need to send the image and video to the app and allow user to download the image and video to their phone Gallery. I am stuck with this! Please do help me.. Thank you..


Solution

  • Here is the function that might help

    saveImage(String url) async {
        
        var response = await Dio()
            .get(url, options: Options(responseType: ResponseType.bytes));
        final result = await ImageGallerySaver.saveImage(
            Uint8List.fromList(response.data),
            quality: 100,
            name: "${widget.id}");
      }
    
    

    in order to use this function you have to install two packages(And them in your pubspec.ymal file) :

    dio: ^3.0.10
    image_gallery_saver: '^1.5.0'