搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目