Link Preview Generator

Pub build CodeFactor License Donate

A cross-platform flutter package to convert your links into rich beautiful previews.
This package is inspired from Any Link Preview package, but the entire parsing & scrapping logic has been re-written to be more robust & to support more links. It also provides control over complete customization of the widget.

Usage

Widget Example

import 'package:link_preview_generator/link_preview_generator.dart';

/// Generate a beautiful link preview card widget
LinkPreviewGenerator(
    bodyMaxLines: 3,
    link: 'https://github.com/ghpranav/link_preview_generator',
    linkPreviewStyle: LinkPreviewStyle.large,
    showGraphic: true,
)

Function Example

import 'package:link_preview_generator/link_preview_generator.dart';

/// Pass the URL to be parsed/scraped
/// to build your own custom widget with parsed data
final WebInfo info = await LinkPreview.scrapeFromURL('https://github.com/ghpranav/link_preview_generator');

/// Description of the page.
final String description = info.description;

/// Domain name of the link.
final String domain = info.domain;

/// Favicon of the page.
final String icon = info.icon;

/// Image URL, if present any in the link.
final String image = info.image;

/// Title of the page.
final String title = info.title;

/// Link preview type of the rule used for scrapping the link.
/// Returns [LinkPreviewType.error] if the scrapping is failed.
final LinkPreviewType type = info.type;

/// Video URL, if present any in the link.
final String video = info.video;

Props & Methods

LinkPreviewGenerator

PropNameDescriptionPropTypevaluerequired
linkURL to display as previewStringtrue
backgroundColorCustomize the background colour of widgetColordefault(Color.fromRGBO(248, 248, 248, 1.0))false
bodyMaxLinesMaximum number of description body linesintdefault(3)false
bodyStyleCustomize the description body styleTextStyleN.Afalse
bodyTextOverflowOverflow type for description body textTextOverflowdefault(TextOverflow.ellipsis)false
borderRadiusBorder radius for the widget carddoubledefault(12.0)false
boxShadowBox shadow for the widget cardList<BoxShadow>false
cacheDurationCache the parsed result for a certain durationDurationdefault(Duration(days: 7))false
errorBodyBody that need to be shown if parsing failsStringdefault(Oops! Unable to parse the url.)false
errorImageImage URL that will be shown if parsing failsStringdefault(A crying semi-soccer ball image)false
errorTitleTitle that need to be shown if parsing failsStringdefault(Something went wrong!)false
errorWidgetWidget shown if parsing fails. Defaults to plain containerWidgetfalse
linkPreviewStyleLink Preview card display styleLinkPreviewStyledefault(large) small,largefalse
placeholderWidgetWidget shown when parsing the linkWidgetfalse
proxyUrlProxy URL to pass that resolve CORS issues on webStringexample(https://cors-anywhere.herokuapp.com/)false
removeElevationTo remove the widget card elevationbooldefault(false) true,falsefalse
showGraphicShow or Hide the image after parsing, if availablebooldefault(true) true,falsefalse
titleStyleCustomize the title styleTextStyleN.Afalse

Contributing

  1. Fork it

  2. Create your feature branch (git checkout -b my-new-feature)

  3. Commit your changes (git commit -am 'Added some feature')

  4. Push to the branch (git push origin my-new-feature)

  5. Create new Pull Request

Contributors

Image of contributors

License

MIT

Libraries