搜尋套件、儲存庫與 APP 分類

套件詳情v1.5.6

flutter_link_preview

這是一個預覽 URL 內容的外掛程式。

近 30 天下載
147
喜歡數
76
Pub 分數
40

安裝套件

flutter pub add flutter_link_preview

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_link_preview 套件讓 Flutter 應用程式能夠顯示 URL 的豐富預覽,從連結的網頁中擷取標題、描述和影像等元資料。它透過在導航前提供視覺上下文,增強了社群媒體和訊息應用的使用者體驗。此外,該套件會分析 URL 的 HTML 內容並擷取相關資訊,支援使用可自訂 UI 元素進行動態呈現。輕巧且能順暢整合至現有專案。

適用情境

  • 社交媒體應用貼文
  • 訊息應用程式URL分享
  • 內容發現功能
  • 部落格或新聞摘要預覽
  • 使用者產生內容驗證

主要特色

  • 自動獲取 URL 元數據
  • 支援圖像、標題和描述預覽
  • 可自定義的 UI 組件
  • 輕量且快速的渲染
  • 適用於任何公開網頁 URL

適合對象

  • 需要豐富URL預覽的應用
  • 開發社交平台的開發者
  • 用戶共享連結的項目
  • 即時內容顯示需要
  • 跨平台移動應用

使用建議

  • 需要互聯網訪問以獲取元數據
  • 在受限制或非公開的URL上可能失敗
  • 性能取決於伺服器回應時間
  • 複雜版面的自訂功能有限
  • 不支援直接嵌入影片

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_link_preview

This is a URL preview plugin that previews the content of a URL

Language: English | 中文简体

Demo

Special feature

  • Use multi-processing to parse web pages, avoid blocking the main process
  • Support for content caching and expiration mechanisms to return results faster
  • Better fault tolerance, multiple ways to find icons, titles, descriptions, image
  • Better support gbk code, no messy code
  • Optimized for large files with better crawl performance
  • Support for second hop authentication with cookies
  • Support gif, video and other content capture
  • Supports custom builder

Getting Started

FlutterLinkPreview(
    url: "https://github.com",
    titleStyle: TextStyle(
        color: Colors.blue,
        fontWeight: FontWeight.bold,
    ),
)

Result:

Result Image

Custom Rendering

Widget _buildCustomLinkPreview(BuildContext context) {
  return FlutterLinkPreview(
    key: ValueKey("${_controller.value.text}211"),
    url: _controller.value.text,
    builder: (info) {
      if (info == null) return const SizedBox();
      if (info is WebImageInfo) {
        return CachedNetworkImage(
          imageUrl: info.image,
          fit: BoxFit.contain,
        );
      }

      final WebInfo webInfo = info;
      if (!WebAnalyzer.isNotEmpty(webInfo.title)) return const SizedBox();
      return Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          color: const Color(0xFFF0F1F2),
        ),
        padding: const EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: <Widget>[
                CachedNetworkImage(
                  imageUrl: webInfo.icon ?? "",
                  imageBuilder: (context, imageProvider) {
                    return Image(
                      image: imageProvider,
                      fit: BoxFit.contain,
                      width: 30,
                      height: 30,
                      errorBuilder: (context, error, stackTrace) {
                        return const Icon(Icons.link);
                      },
                    );
                  },
                ),
                const SizedBox(width: 8),
                Expanded(
                  child: Text(
                    webInfo.title,
                    overflow: TextOverflow.ellipsis,
                  ),
                ),
              ],
            ),
            if (WebAnalyzer.isNotEmpty(webInfo.description)) ...[
              const SizedBox(height: 8),
              Text(
                webInfo.description,
                maxLines: 5,
                overflow: TextOverflow.ellipsis,
              ),
            ],
            if (WebAnalyzer.isNotEmpty(webInfo.image)) ...[
              const SizedBox(height: 8),
              CachedNetworkImage(
                imageUrl: webInfo.image,
                fit: BoxFit.contain,
              ),
            ]
          ],
        ),
      );
    },
  );
}

Result Image

Sample code

Click here for a detailed example.

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案