Skip to content

Commit 0cb8bc4

Browse files
committed
Fixed feedback
1 parent 1362778 commit 0cb8bc4

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class MyHomePage extends StatelessWidget {
3838
padding: const EdgeInsets.all(16),
3939
child: AnnotatedText(
4040
text:
41-
'|Flutter(onFlutterTap)| example of using a Rich Text with annotations with multiple |tap(onTap)| actions.\nThis tap |action(action)| does nothing. And |action| without () does nothing as well',
41+
'[Flutter](onFlutterTap) example of using a Rich Text with annotations with multiple [tap](onTap) actions.\nThis tap [action](action) does nothing. And [action] without () does nothing as well',
4242
defaultStyle: const TextStyle(color: Colors.black),
4343
annotationStyle: const TextStyle(color: Colors.blue),
4444
actions: {

lib/ui/annotated_text/annotated_text.dart

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@ import 'package:flutter/gestures.dart';
22
import 'package:flutter/material.dart';
33

44
/// A widget that displays a text with inline actions.
5-
/// Supported formats: |text(action)| or |text|
5+
/// Supported formats: [text](action) or [text]
66
/// This way translations can be done with inline actions.
77
///
88
/// The text is displayed as a [RichText] widget.
99
/// The annotations are displayed as a [TextSpan] widget with optionally a [TapGestureRecognizer] attached to it (if the action is not null).
1010
/// The [actions] map is used to map the action name to the action to perform when the text is tapped.
1111
/// The [defaultStyle] is the style of the default text.
1212
/// The [annotationStyle] is the style of the annotated text.
13+
///
14+
/// [some text] only highlights the text, but does not trigger an action.
15+
/// [some text](action) highlights the text and triggers the action when tapped.
16+
/// [some text](action) without a defined action for the exact name 'action' will not trigger an action.
17+
///
18+
/// Example:
19+
/// ```dart
20+
/// AnnotatedText(
21+
/// text: 'Hello [world](onWorldTapped)',
22+
/// actions: {'onWorldTapped': () => print('world')},
23+
/// defaultStyle: TextStyle(color: Colors.black),
24+
/// annotationStyle: TextStyle(color: Colors.blue),
25+
/// )
26+
/// ```
1327
class AnnotatedText extends StatelessWidget {
1428
/// Creates a widget that displays a text with annotations.
1529
const AnnotatedText({
@@ -35,12 +49,7 @@ class AnnotatedText extends StatelessWidget {
3549
@override
3650
Widget build(BuildContext context) {
3751
return RichText(
38-
text: _buildTextSpan(
39-
text: text,
40-
defaultStyle: defaultStyle,
41-
annotationStyle: annotationStyle,
42-
actions: actions,
43-
),
52+
text: _buildTextSpan(text: text, defaultStyle: defaultStyle, annotationStyle: annotationStyle, actions: actions),
4453
);
4554
}
4655
}
@@ -51,8 +60,8 @@ TextSpan _buildTextSpan({
5160
required TextStyle annotationStyle,
5261
Map<String, VoidCallback>? actions,
5362
}) {
54-
/// matches |text(function)| with an action, or |text| without an action
55-
final regex = RegExp(r'\|(.+?)(?:\((.*?)\))?\|');
63+
/// matches [text](action) with an action, or [text] without an action
64+
final regex = RegExp(r'\[([^\]]+?)\](?:\((.*?)\))?');
5665
final spans = <TextSpan>[];
5766
var currentIndex = 0;
5867

0 commit comments

Comments
 (0)