I am trying to load some images into a gridview. Each GridTile contains a container with a decoration that uses a NetworkImage. All the images I'm using are stored in google drive and the problem is that for some reason, flutter does not like Google Drive urls. I've tried the following urls:
None of the above is working. It throws the following error:
The following _Exception was thrown resolving an image codec: Exception: Could not instantiate image codec.
What I've noticed is that all of those urls end up redirecting to another link, probably where the image is cached. Is that the reason why is not working? If that is so, how can I force it to follow redirects?
This is the relevant piece of code:
String imgUrl = "https://drive.google.com/file/d/$fileId/view";
GridTile(
child: InkWell(
onTap: () {
openDriveImage(fileId);
},
child: Container(
margin: EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black38,
),
shape: BoxShape.rectangle,
image: DecorationImage(
fit: BoxFit.fitWidth,
image: NetworkImage(imgUrl),
),
),
),
),
How Embed Works? Go to drive.google.com, right-click any image file, and choose Get Link to get a shareable link of that image. Make sure that the access is set to Anyone on the internet with this link can view. Paste that file link in the box below to generate the HTML embed code.
You upload an image file to Google Drive and make that file public. Google Drive will now generate a high-resolution thumbnail image of the uploaded file that you can directly embed on your website or emails.
1. Right click on the selected image in Google Drive 2. Select “Get Shareable link” 3. The link of the image is copied.
Here are the steps:
Right click the image and click Share
as shown below;
In the dialog that appears, make sure the option selected from the dropdown is
Anyone with the link can view
as shown below:
After, click Copy link
and then paste it somewhere
It should be something like this https://drive.google.com/file/d/1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj/view?usp=sharing
which is in the format
https://drive.google.com/file/d/<FILE_ID>/view?usp=sharing
Copy the <FILE_ID> which in my case is 1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj
https://drive.google.com/uc?export=view&id=<FILE_ID>
https://drive.google.com/uc?export=view&id=1VdjEgb0aZl9IZa2jOzGU5_SNbmlmeiCj
NetworkImage()
or Image.network()
widget and your doneIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With