Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreviewData is Empty and no preview #61

Open
nc-jeni opened this issue Apr 24, 2024 · 1 comment
Open

PreviewData is Empty and no preview #61

nc-jeni opened this issue Apr 24, 2024 · 1 comment

Comments

@nc-jeni
Copy link

nc-jeni commented Apr 24, 2024

The following code is placed on my StatefulWidget.

    LinkPreview(
      enableAnimation: true,
      onPreviewDataFetched: (data) {
        print(data);  // data is empty
        setState(() {
          httpdata = data;
        });
      },
      previewData: httpdata,
      text: s, // the url is passed here
      width: MediaQuery.of(context).size.width * 0.7,
    ),

Called with two URLs on the Web platform I get the following response in the data parameter and (of course) no preview is shown, but why is the PreviewData object empty? I have a feeling that the data are never fetched because of an async call somewhere in the flutter_link_previewer library?

_PreviewData(null, null, https://dr.dk, null)
_PreviewData(null, null, https://tv2.dk, null)

An error comes in getPreviewData when http.get is called and it goes to the catch block.

[log] XMLHttpRequest error.

Please have a look at this post for solving the problem: dart-flutter-http-request-raises-xmlhttprequest-error as it is probably the issue???

@nc-jeni nc-jeni changed the title PreviewData is Empty PreviewData is Empty and no preview Apr 24, 2024
@nc-jeni
Copy link
Author

nc-jeni commented Apr 25, 2024

I figured it out.
Running from a mobile platform it works, but from web it does not.
The reason was because of cross cors.

headers: {
  "Access-Control-Allow-Origin": "*",
  "Content-Type": "application/json",
  "Accept": "*/*"
}

Adding the option using such request headers might be an idea? @demchenkoalex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant