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

Wrong Image #55

Open
ribalassaf opened this issue Nov 28, 2023 · 5 comments
Open

Wrong Image #55

ribalassaf opened this issue Nov 28, 2023 · 5 comments

Comments

@ribalassaf
Copy link

I'm using this package inside of a chat screen
when I send a link it fetches the image of the previously sent link .

@demchenkoalex
Copy link
Member

I just tried the example in the chat UI package and two links I sent had correct data. Can you share more information please? how do you use this package?

@Astaxask
Copy link

Astaxask commented Jan 1, 2024

The code works just fine. However, every time a link is posted in chat the UI gets rebuilt which is not a good UX design.

@demchenkoalex
Copy link
Member

@Astaxask unfortunately this is how Flutter works. Every time you add something to the list view, all visible items are rebuilt :/

@Astaxask
Copy link

Astaxask commented Jan 2, 2024

You might want to have a look at "any_link_preview". They managed to optimize the solution without rebuilding the UI. The thing about that library, though, is the way images are displayed. You guys have a better preview design. But if only you can find a way around rebuilding the UI every time and implement the same functionality as "any_link_preview".

@demchenkoalex
Copy link
Member

we are talking about different things. You were saying

However, every time a link is posted in chat the UI gets rebuilt which is not a good UX design

here is a flutter documentation for a list that can add items to it https://api.flutter.dev/flutter/widgets/AnimatedList-class.html if you add print("rebuilt"); to the line 186 of the example you will see

rebuilt
rebuilt
rebuilt

in the console, because there are 3 items. Next, if you press + to add a new item you will see

rebuilt
rebuilt
rebuilt
rebuilt
rebuilt
rebuilt
rebuilt

3 + 4, because flutter rebuilds everything visible on screen when new items is added, no library can change that. This is what happens with this preview or will happen to any other preview.

If you mean that you add a link (for example apple.com) and it shows a preview and then you add next message and previous preview gets rebuilt and UI jumps, then check the README

LinkPreview(
  enableAnimation: true,
  onPreviewDataFetched: (data) {
    setState(() {
      // Save preview data to the state              
    });
  },
  previewData: _previewData, // Pass the preview data from the state
  text: 'https://flyer.chat',
  width: MediaQuery.of(context).size.width,
)

onPreviewDataFetched you should save the fetched preview data and pass it to the previewData param, this way when flutter will rebuilt the list item (and it will) library will read from the cached previewData and not jump/fetch it again.

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

3 participants