any_link_preview 1.0.7 any_link_preview: ^1.0.7 copied to clipboard
A flutter package/plugin which will help you to show preview of web links. Can be useful in chat for example.
import 'package:any_link_preview/any_link_preview.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
/// I picked these links & images from internet
final String _errorImage =
"https://i.ytimg.com/vi/z8wrRRR7_qU/maxresdefault.jpg";
final String _url1 =
"https://www.espn.in/football/soccer-transfers/story/4163866/transfer-talk-lionel-messi-tells-barcelona-hes-more-likely-to-leave-then-stay";
final String _url2 =
"https://speakerdeck.com/themsaid/the-power-of-laravel-queues";
final String _url3 =
"https://twitter.com/laravelphp/status/1222535498880692225";
final String _url4 = "https://www.youtube.com/watch?v=W1pNjxmNHNQ";
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Any Link Preview')),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
AnyLinkPreview(
link: _url1,
displayDirection: UIDirection.UIDirectionHorizontal,
cache: Duration(hours: 1),
backgroundColor: Colors.grey[300],
errorWidget: Container(
color: Colors.grey[300],
child: Text('Oops!'),
),
errorImage: _errorImage,
),
SizedBox(height: 25),
AnyLinkPreview(
link: _url2,
displayDirection: UIDirection.UIDirectionHorizontal,
showMultimedia: false,
bodyMaxLines: 5,
bodyTextOverflow: TextOverflow.ellipsis,
titleStyle: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 15,
),
bodyStyle: TextStyle(color: Colors.grey, fontSize: 12),
),
SizedBox(height: 25),
AnyLinkPreview(
displayDirection: UIDirection.UIDirectionHorizontal,
link: _url3,
errorBody: 'Show my custom error body',
errorTitle: 'Next one is youtube link, error title',
),
SizedBox(height: 25),
AnyLinkPreview(link: _url4),
],
),
),
),
);
}
}