Home > Net >  How to read an image from a non-image link in Flutter?
How to read an image from a non-image link in Flutter?

Time:11-15

I want to read images from network. However, what I want is a bit different than normal. Normally, everyone can use Image.network to read images from image links. However, what I want is to read images from non-image links, such as this link.

I tried using Image.network to do this without success.

I didn't include the code because I don't think the code has anything to do with this.

If you need more info feel free to leave a comment!

How to read an image from a non-image link in Flutter? I would appreciate any help. Thank you in advance!

CodePudding user response:

If you need to preview the link, you might be looking for a link previewer package like this maybe flutter_link_previewer

CodePudding user response:

Potentially a repost for : Flutter, fetching specfic image from website

In this case you just need to extract all the elements having the word thumb in them which can be done by the method as described in the link above :

void _getData() async {
        final response =
            await http.get('https://www.bloomberg.com/news/articles/2022-11-15/russia-expected-to-agree-to-extend-black-sea-grain-export-deal');
        dom.Document document = parser.parse(response.body);
        final elements = document.getElementsByClassName('thumb');

        setState(() {
          list = elements
              .map((element) =>
                  element.getElementsByTagName("img")[0].attributes['src'])
              .toList();
        });
      }

What this is doing is just creating a list of all the images available in the source code of the particular URL that you're entering.

  • Related