How do you download an image from the internet onto a file in Flutter?

185 views Asked by At

I'm making a Flutter project where an image is displayed in listview and the user can share, favourite or download the image. I'm stuck on the downloading part. Is it possible to save an image file onto the phone's storage for offline use?

What I want to happen is I can create and write an image file

Future<String> get _localPath async {
  final directory = await getApplicationDocumentsDirectory();
  return directory.path;
}

Future<File> get _localFile async {
  final path = await _localPath;
  return File('$path/$title.txt');
}

// Write an image by obtaining an image through a URL

and then be able to access it through

Image.file('$path/$title.txt')
0

There are 0 answers