Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yungzhu/flutter_link_preview
This is a Flutter URL preview plugin for Flutter that previews the content of a URL
https://github.com/yungzhu/flutter_link_preview
dart flutter gif linkpreview
Last synced: 26 days ago
JSON representation
This is a Flutter URL preview plugin for Flutter that previews the content of a URL
- Host: GitHub
- URL: https://github.com/yungzhu/flutter_link_preview
- Owner: yungzhu
- License: mit
- Created: 2020-05-14T12:24:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-24T08:43:40.000Z (about 2 years ago)
- Last Synced: 2024-09-30T09:22:24.906Z (about 1 month ago)
- Topics: dart, flutter, gif, linkpreview
- Language: Dart
- Homepage:
- Size: 1.12 MB
- Stars: 69
- Watchers: 4
- Forks: 62
- Open Issues: 19
-
Metadata Files:
- Readme: README-ZH.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# flutter_link_preview
这是一个网址预览插件,可以预览网址的内容。
文档语言: [English](README.md) | [中文简体](README-ZH.md)
![Demo](images/web1.png)
## 特色功能
- 采用多进程解析网页,避免阻塞主进程
- 支持内容缓存及过期机制,能更快地返回结果
- 更好的容错能力,多种方式查找 icon,title,descriptions,image
- 更好的支持中文编码,没有乱码
- 对大文件进行优化,有更好的抓取性能
- 支持携带 cookies 进行二次跳转验证
- 支持 gif,视频 等内容抓取
- 支持自定义渲染## 开始入门
```dart
FlutterLinkPreview(
url: "https://github.com",
titleStyle: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
)
```结果:
![Result Image](images/web2.png)
## 自定义渲染
```dart
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: [
Row(
children: [
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](images/web3.png)
## 示例代码
[点击这里查看详细示例](example/lib/main.dart).