2

How can I get a File from an ImageProvider?

ImageProvider imageProvider = NetworkImage(networkUrl);
File file = imageProvider ?

1 Answer 1

0

Although ImageProvider with NetworkImage renders the content of your network image URL, it doesn't have direct APIs or easy way for you to be able to convert it to a File object. With that said, you can still manually cache (or download) the image/s and get the download stream.

As far as I can understand your question, you are trying to access the network image URL as a File object. Instead of using ImageProvider, you can take a look at the flutter_cache_manager, which is a plugin used for downloading and caching files locally, and save it for later use.

Example Usage

  1. Downloading network image file from URL
await DefaultCacheManager().downloadFile(url);
  1. Retrieving File object from the cache dir
// Retrieving File object
var file = await DefaultCacheManager().getSingleFile(imageUrl);

// File object available for use
// Eg. Reading file as string
file.readAsStringSync(...);

Further reading

Sign up to request clarification or add additional context in comments.

9 Comments

Using getSingleFile(url), I'm getting an error : ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method getDatabasesPath on channel com.tekartik.sqflite)
What Flutter SDK version are you using?
flutter_windows_v1.9.1+hotfix.6
Is that the only error message you can see from the logs?
That is the first message that appears and then it gets repeated.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.