Skip to content

Commit

Permalink
Update package documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Bedre <bedrepranav@gmail.com>
  • Loading branch information
ghpranav committed Jul 15, 2021
1 parent 5592ec9 commit d4a9ddf
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 24 deletions.
98 changes: 87 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,96 @@
# link_preview_generator
# Link Preview Generator

[![Pub](https://img.shields.io/pub/v/link_preview_generator)](https://pub.dartlang.org/packages/link_preview_generator)
[![build](https://github.com/ghpranav/link_preview_generator/workflows/build/badge.svg)](https://github.com/ghpranav/link_preview_generator/actions?query=workflow%3Abuild)
[![CodeFactor](https://www.codefactor.io/repository/github/ghpranav/link_preview_generator/badge)](https://www.codefactor.io/repository/github/ghpranav/link_preview_generator)
[![License](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)
[![Platform](https://img.shields.io/badge/platform-flutter-ff69b4.svg)](https://github.com/ghpranav/link_preview_generator)
[![Donate](https://img.shields.io/badge/Donate-UPI-green.svg)](https://upayi.me/bedrepranav@okhdfcbank)

A Flutter package to convert your links into beautiful previews.
A cross-platform flutter package to convert your links into rich beautiful previews. <br>
This package is inspired from [Any Link Preview](https://pub.dartlang.org/packages/any_link_preview) package, but the entire parsing & scrapping logic has been re-written to be more robust & to support more links.

## Getting Started
## Usage

This project is a starting point for a Dart
[package](https://flutter.dev/developing-packages/),
a library module containing code that can be shared easily across
multiple Flutter or Dart projects.
### Widget Example

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
```dart
import 'package:link_preview_generator/link_preview_generator.dart';
LinkPreviewGenerator(
bodyMaxLines: 3,
link: 'https://github.com/ghpranav/link_preview_generator',
linkPreviewStyle: LinkPreviewStyle.large,
showGraphic: true,
)
```

### Function Example

```dart
import 'package:link_preview_generator/link_preview_generator.dart';
final WebInfo info = await LinkPreview.scrape(url);
/// 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

| PropName | Description | PropType | value | required |
| --------------------- | ---------------------------------------------------------- | ----------------- | ----------------------------------------------------------------------------------------------------------------------------------- | -------- |
| **link** | URL to display as preview | String | | `true` |
| **backgroundColor** | Customize the background colour of widget | Color | default(`Color.fromRGBO(248, 248, 248, 1.0)`) | `false` |
| **bodyMaxLines** | Maximum number of description body lines | int | default(`3`) | `false` |
| **bodyStyle** | Customize the description body style | TextStyle | N.A | `false` |
| **bodyTextOverflow** | Overflow type for description body text | TextOverflow | default(`TextOverflow.ellipsis`) | `false` |
| **borderRadius** | Border radius for the widget card | double | default(`12.0`) | `false` |
| **boxShadow** | Box shadow for the widget card | List<`BoxShadow`> | | `false` |
| **cacheDuration** | Cache the parsed result for a certain duration | Duration | default(`Duration(days: 7)`) | `false` |
| **errorBody** | Body that need to be shown if parsing fails | String | default(`Oops! Unable to parse the url.`) | `false` |
| **errorImage** | Image URL that will be shown if parsing fails | String | default([A crying semi-soccer ball image](https://raw.githubusercontent.com/ghpranav/link_preview_generator/main/assets/giphy.gif)) | `false` |
| **errorTitle** | Title that need to be shown if parsing fails | String | default(`Something went wrong!`) | `false` |
| **errorWidget** | Widget shown if parsing fails. Defaults to plain container | Widget | | `false` |
| **linkPreviewStyle** | Link Preview card display style | LinkPreviewStyle | default(`large`) `small`,`large` | `false` |
| **placeholderWidget** | Widget shown when parsing the link | Widget | | `false` |
| **proxyUrl** | Proxy URL to pass that resolve CORS issues on web | String | example(`https://cors-anywhere.herokuapp.com/`) | `false` |
| **removeElevation** | To remove the widget card elevation | bool | default(`false`) `true`,`false` | `false` |
| **showGraphic** | Show or Hide the image after parsing, if available | bool | default(`true`) `true`,`false` | `false` |
| **titleStyle** | Customize the title style | TextStyle | N.A | `false` |

## 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

## License

[MIT](LICENSE)
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
// List of links to preview.
List<String> get urls => const [
'https://flyer.chat',
'https://github.com/ghpranav/link_preview_generator',
'https://www.espn.in/football/soccer-transfers/story/4163866/transfer-talk-lionel-messi-tells-barcelona-hes-more-likely-to-leave-then-stay',
'https://speakerdeck.com/themsaid/the-power-of-laravel-queues',
'https://twitter.com/laravelphp/status/1222535498880692225',
Expand Down
25 changes: 13 additions & 12 deletions lib/src/widgets/link_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:url_launcher/url_launcher.dart';

/// A widget to convert your links into beautiful previews.
class LinkPreviewGenerator extends StatefulWidget {
/// Customize the background colour
/// Customize the background colour.
/// Deaults to `Color.fromRGBO(248, 248, 248, 1.0)`.
final Color backgroundColor;

Expand All @@ -25,7 +25,7 @@ class LinkPreviewGenerator extends StatefulWidget {
final TextOverflow bodyTextOverflow;

/// BorderRadius for the card.
/// Deafults to `12`.
/// Deafults to `12.0`.
final double borderRadius;

/// Box shadow for the card.
Expand All @@ -36,24 +36,24 @@ class LinkPreviewGenerator extends StatefulWidget {
/// offset: Offset(0, 3),)]`.
final List<BoxShadow>? boxShadow;

/// Cache result time, default cache `30 days`.
/// Cache result time, default cache `7 days`.
final Duration cacheDuration;

/// Body that need to be shown if something goes wrong.
/// Body that need to be shown if parsing fails.
/// Deaults to `Oops! Unable to parse the url.`
final String errorBody;

/// Image URL that will be shown if something goes wrong
/// Image URL that will be shown if parsing fails
/// & when multimedia enabled & no meta data is available.
/// Deaults to `A semi-soccer ball image that looks like crying`.
/// https://github.com/ghpranav/link_preview_generator/blob/main/assets/giphy.gif?raw=true1
/// Deaults to `A crying semi-soccer ball image`.
/// https://raw.githubusercontent.com/ghpranav/link_preview_generator/main/assets/giphy.gif
final String errorImage;

/// Title that need to be shown if something goes wrong.
/// Title that need to be shown if parsing fails.
/// Deaults to `Something went wrong!`
final String errorTitle;

/// Widget that needs to be shown if something goes wrong.
/// Widget that needs to be shown if parsing fails.
/// Defaults to plain container with given background colour.
final Widget? errorWidget;

Expand All @@ -70,6 +70,7 @@ class LinkPreviewGenerator extends StatefulWidget {
final Widget? placeholderWidget;

/// Proxy URL to pass that resolve CORS issues on web.
/// For example, `https://cors-anywhere.herokuapp.com/` .
final String? proxyUrl;

/// To remove the card elevation set it to `true`.
Expand All @@ -87,7 +88,7 @@ class LinkPreviewGenerator extends StatefulWidget {
const LinkPreviewGenerator({
Key? key,
required this.link,
this.cacheDuration = const Duration(days: 30),
this.cacheDuration = const Duration(days: 7),
this.titleStyle,
this.bodyStyle,
this.linkPreviewStyle = LinkPreviewStyle.large,
Expand All @@ -100,9 +101,9 @@ class LinkPreviewGenerator extends StatefulWidget {
this.errorWidget,
this.errorBody = 'Oops! Unable to parse the url.',
this.errorImage =
'https://github.com/ghpranav/link_preview_generator/blob/main/assets/giphy.gif?raw=true',
'https://raw.githubusercontent.com/ghpranav/link_preview_generator/main/assets/giphy.gif',
this.errorTitle = 'Something went wrong!',
this.borderRadius = 12,
this.borderRadius = 12.0,
this.boxShadow,
this.removeElevation = false,
}) : super(key: key);
Expand Down

0 comments on commit d4a9ddf

Please sign in to comment.