Skip to content

Feat/link preview v2#784

Merged
demchenkoalex merged 7 commits intoflyerhq:mainfrom
nicolasbraun:feat/link_preview_v2
May 22, 2025
Merged

Feat/link preview v2#784
demchenkoalex merged 7 commits intoflyerhq:mainfrom
nicolasbraun:feat/link_preview_v2

Conversation

@nicolasbraun
Copy link
Copy Markdown
Contributor

@nicolasbraun nicolasbraun commented May 20, 2025

Motivation

Aims to fix #758 and allow easier implementation of linkPreviews in the chat.
This relies on the following PR flyerhq/flutter_link_previewer#63 in flutter_link_previewer , I made it there for easier review, but once it's ok we can move it in this monorepo.

LinkPreview

  • Made LinkPreview depend on chatcore
  • Reworked the methods to return null if no preview since the new model link property is not optional
  • Added back the image information
  • Reworked the layout to allow to hide specifiy items, especially the linkify text which "repeats" the chatMessage text
  • ⚠️ Made width optional (default to infinity) and used a layoutBuilder to constrain the _imageWidget

ChatUi

  • Added a builder for the linkPreview
  • Adapted FlyerChatMessage and SimpleMessage to display the Preview
  • No default implementation => did not want to make them depends on flutter_link_previewer + the logic to fetch or not preview is to be decided by the user.

Implementation example

linkPreviewBuilder: (context, message) {
          final metadataLinkPreviewFetchedKey = 'linkPreviewDataFetched';
          final isLinkPreviewDataFetched =
              message.metadata?.containsKey(metadataLinkPreviewFetchedKey) ??
                  false;

          if (message.linkPreviewData != null || !isLinkPreviewDataFetched) {
            return Column(
              children: [
                Divider(
                  height: 0.5,
                  color: Colors.white,
                ),
                LinkPreview(
                  text: message.text,
                  linkPreviewData: message.linkPreviewData,
                  hideDescription: false,
                  hideText: false,
                  hideTitle: false,
                  linkStyle: TextStyle().copyWith(color: Colors.white),
                  openOnPreviewImageTap: true,
                  openOnPreviewTitleTap: true,
                  onLinkPreviewDataFetched: (linkPreviewData) {
                    _controller?.updateMessage(
                      message,
                      message.copyWith(
                        metadata: {
                          ...message.metadata ?? {},
                          metadataLinkPreviewFetchedKey: true,
                        },
                        linkPreviewData: linkPreviewData,
                      ),
                    );
                  },
                ),
              ],
            );
          }
          return null;
        },
     

Questions / notes

  1. Not sure why the display as row is conditionned to the image being square? Maybe we could add an option to force a row/colum render
  2. Understanding the layout was quite harsh, I tried to make it a little bit more readable

Screenshots

Preview Description
Everything showed
Hidden text
Title and image only
No img
img only
fake 1 ratio => row render

@demchenkoalex demchenkoalex merged commit b65060e into flyerhq:main May 22, 2025
1 check passed
@demchenkoalex
Copy link
Copy Markdown
Member

some changes I made after merging: c922a0c

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

Successfully merging this pull request may close these issues.

Implement linkPreview in v2

2 participants