Skip to content

Commit a307c9e

Browse files
committed
fix: add example to the flutter_link_previewer
1 parent e267c27 commit a307c9e

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
```dart
2+
import 'package:flutter/material.dart';
3+
import 'package:flutter_link_previewer/flutter_link_previewer.dart';
4+
import 'package:flutter_chat_core/flutter_chat_core.dart' show LinkPreviewData;
5+
6+
class MyChatBubble extends StatefulWidget {
7+
const MyChatBubble({super.key, required this.message});
8+
9+
final String message;
10+
11+
@override
12+
State<MyChatBubble> createState() => _MyChatBubbleState();
13+
}
14+
15+
class _MyChatBubbleState extends State<MyChatBubble> {
16+
LinkPreviewData? _linkPreviewData;
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
return Container(
21+
padding: const EdgeInsets.all(16),
22+
child: Column(
23+
crossAxisAlignment: CrossAxisAlignment.start,
24+
children: [
25+
Text(widget.message),
26+
LinkPreview(
27+
// The text that should be parsed to find the first URL
28+
text: widget.message,
29+
// Pass the cached preview data to avoid re-fetching
30+
linkPreviewData: _linkPreviewData,
31+
// Callback to store the fetched preview data
32+
onLinkPreviewDataFetched: (data) {
33+
setState(() {
34+
_linkPreviewData = data;
35+
});
36+
},
37+
// For a chat bubble, you would pass the message text here
38+
// to align the preview with the text bubble.
39+
parentContent: widget.message,
40+
// Customization example
41+
borderRadius: 4,
42+
sideBorderColor: Colors.white,
43+
sideBorderWidth: 4,
44+
insidePadding: const EdgeInsets.fromLTRB(12, 8, 8, 8),
45+
outsidePadding: const EdgeInsets.symmetric(vertical: 4),
46+
titleTextStyle: const TextStyle(
47+
fontWeight: FontWeight.bold,
48+
fontSize: 20,
49+
),
50+
),
51+
],
52+
),
53+
);
54+
}
55+
}
56+
57+
```

packages/flutter_link_previewer/lib/src/link_preview.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,14 @@ class _LinkPreviewState extends State<LinkPreview>
469469
}
470470
}
471471

472-
enum LinkPreviewImagePosition { bottom, side }
472+
/// The position of the image in the link preview.
473+
enum LinkPreviewImagePosition {
474+
/// The image is displayed at the bottom of the preview.
475+
bottom,
476+
477+
/// The image is displayed on the side of the preview.
478+
side,
479+
}
473480

474481
extension on LinkPreviewData {
475482
bool hasTitle({bool hide = false}) =>

0 commit comments

Comments
 (0)