-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_pattern.dart
29 lines (26 loc) · 1.02 KB
/
custom_pattern.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import 'package:flutter/material.dart';
import 'package:custom_text/custom_text.dart';
class CustomPatternExample extends StatelessWidget {
const CustomPatternExample(this.output);
final void Function(String) output;
@override
Widget build(BuildContext context) {
return CustomText(
'Hello world! #CustomText',
definitions: const [
TextDefinition(
// Matcher for hashtags (provided a hashtag is defined as a string
// that starts with "#" followed by an alphabet and then alpha-
// numerics, and is enclosed with white spaces)
matcher: PatternMatcher(r'#[a-zA-Z][a-zA-Z0-9]{1,}(?=\s|$)'),
// TODO: Replace above with below if Safari supports lookbehind.
// matcher:
// PatternMatcher(r'(?<=\s|^)\#[a-zA-Z][a-zA-Z0-9]{1,}(?=\s|$)'),
),
],
matchStyle: const TextStyle(color: Colors.lightBlue),
tapStyle: const TextStyle(color: Colors.lightGreen),
onTap: (details) => output(details.actionText),
);
}
}