linked_text 1.0.0
linked_text: ^1.0.0 copied to clipboard
A Flutter widget that renders text with interpolated tappable links using a simple template syntax.
linked_text #
A Flutter widget that renders text with interpolated tappable links using a simple template syntax.
Features #
- Simple template syntax for embedding links in text
- Auto-indexed (
{{link}}) and explicitly indexed ({N{link}}) placeholders - Default URL launching via
url_launcheror customonTapcallback - Semantic labels for accessibility
- Customizable text and link styles
- Proper gesture recognizer lifecycle management
Installation #
dependencies:
linked_text: ^1.0.0
Usage #
Basic usage with a single link #
LinkedText(
text: 'Visit the {{Flutter website}} for more info.',
urls: ['https://flutter.dev'],
urlLabels: ['Link to Flutter website'],
)
Multiple auto-indexed links #
Un-indexed placeholders are automatically assigned sequential indices:
LinkedText(
text: '{{Privacy Policy}} | {{Terms of Service}}',
urls: [
'https://example.com/privacy',
'https://example.com/terms',
],
urlLabels: [
'Link to Privacy Policy',
'Link to Terms of Service',
],
)
Explicitly indexed links #
Use {N{text}} syntax (1-based) to control which URL each placeholder maps to:
LinkedText(
text: 'Built with {1{Flutter}}, powered by {2{Dart}}.',
urls: [
'https://flutter.dev',
'https://dart.dev',
],
urlLabels: [
'Link to Flutter',
'Link to Dart',
],
)
Custom tap handling #
LinkedText(
text: 'Read the {{documentation}}.',
urls: ['https://example.com/docs'],
urlLabels: ['Link to documentation'],
onTap: (url, index) {
// Custom handling instead of launching URL
print('Tapped link $index: $url');
},
)
Custom styles #
LinkedText(
text: 'Check out {{this link}}.',
urls: ['https://example.com'],
urlLabels: ['Example link'],
style: TextStyle(fontSize: 14, color: Colors.grey),
linkStyle: TextStyle(
fontSize: 14,
color: Colors.blue,
decoration: TextDecoration.underline,
),
textAlign: TextAlign.center,
)
Template Syntax #
| Syntax | Description | Example |
|---|---|---|
{{text}} |
Auto-indexed link (0-based, sequential) | {{Click here}} |
{N{text}} |
Explicitly indexed link (N is 1-based) | {1{Click here}} |
API Reference #
See the API documentation for full details.