Flutter save a network image to local directory

后端 未结 10 671
情歌与酒
情歌与酒 2020-12-24 08:52

In Flutter how to save an image from network to the local directory.

I am new to encoding and decoding images. Can anyone point me in the right direction?

10条回答
  •  醉酒成梦
    2020-12-24 09:38

    To save the network image in local system you need to use ImagePickerSave dart plugin. Add the dart plugin in pub.yaml file: image_picker_saver: ^0.1.0 and call below code to save the image. URL is the image URL of network image

    void _onImageSaveButtonPressed(String url) async {
      print("_onImageSaveButtonPressed");
      var response = await http
          .get(url);
    
      debugPrint(response.statusCode.toString());
    
      var filePath = await ImagePickerSaver.saveFile(
          fileData: response.bodyBytes);
      var savedFile= File.fromUri(Uri.file(filePath));
    }
    

提交回复
热议问题