parsed_text 0.0.2
parsed_text: ^0.0.2 copied to clipboard
A lightweight Flutter widget to detect patterns in text (like links, hashtags, or mentions) and style or make them tappable.
ParsedText A lightweight Flutter widget to detect patterns in text (like links, hashtags, or mentions) and style or make them tappable.
Features #
- Parse multiple regex patterns in a single text
- Style matched patterns differently
- Add tap handlers (onTap) to matched text
- Optionally render matched text dynamically (e.g., transform @user → User)
- Simple, dependency-free, fully customizable
Installation #
Add to your pubspec.yaml: dependencies: parsed_text: ^1.0.0
Usage #
Import it:
import 'package:flutter/material.dart';
import 'package:parsed_text/parsed_text.dart';
class ExamplePage extends StatelessWidget {
const ExamplePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('ParsedText Example')),
body: Center(
child: ParsedText(
text:
'Check out @frederick and visit https://flutter.dev for more info! #FlutterRocks 💪',
style: const TextStyle(fontSize: 16, color: Colors.black87),
rules: [
ParseRule(
pattern: RegExp(r'@(\w+)'),
style: const TextStyle(color: Colors.blue),
onTap: (username) {
debugPrint('Tapped user: $username');
},
),
ParseRule(
pattern: RegExp(r'https?://[^\s]+'),
style: const TextStyle(color: Colors.green),
onTap: (url) {
debugPrint('Tapped link: $url');
},
),
ParseRule(
pattern: RegExp(r'#(\w+)'),
style: const TextStyle(color: Colors.purple),
onTap: (hashtag) {
debugPrint('Tapped hashtag: $hashtag');
},
),
],
),
),
);
}
}
Test #
fvm flutter test --coverage or flutter test --coverage