Skip to content

Commit 831af80

Browse files
committed
improve/add pill builder for customization
1 parent a2e83b9 commit 831af80

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/flutter_html.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Html extends StatelessWidget {
3232
this.getCodeLanguage,
3333
this.setCodeLanguage,
3434
this.inlineSpanEnd,
35+
this.pillBuilder,
3536
}) : super(key: key);
3637

3738
final String data;
@@ -57,6 +58,7 @@ class Html extends StatelessWidget {
5758
/// Setting and getting code langauge cache
5859
final SetCodeLanguage? setCodeLanguage;
5960
final GetCodeLanguage? getCodeLanguage;
61+
final PillBuilder? pillBuilder;
6062

6163
final InlineSpan? inlineSpanEnd;
6264

@@ -89,6 +91,7 @@ class Html extends StatelessWidget {
8991
setCodeLanguage: setCodeLanguage,
9092
getCodeLanguage: getCodeLanguage,
9193
inlineSpanEnd: inlineSpanEnd,
94+
pillBuilder: pillBuilder,
9295
),
9396
),
9497
);

lib/text_parser.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef OnPillTap = void Function(String identifier);
2424
typedef GetMxcUrl = String Function(String mxc, double? width, double? height,
2525
{bool? animated});
2626
typedef GetPillInfo = Future<Map<String, dynamic>> Function(String identifier);
27+
typedef PillBuilder = Widget? Function(String identifier, String url, OnPillTap? onTap, GetMxcUrl? getMxcUrl);
2728

2829
const OFFSET_TAGS_FONT_SIZE_FACTOR =
2930
0.7; //The ratio of the parent font for each of the offset tags: sup or sub
@@ -105,6 +106,7 @@ class TextParser extends StatelessWidget {
105106
this.setCodeLanguage,
106107
this.getCodeLanguage,
107108
this.inlineSpanEnd,
109+
this.pillBuilder,
108110
});
109111

110112
final double indentSize = 10.0;
@@ -127,6 +129,7 @@ class TextParser extends StatelessWidget {
127129
final SetCodeLanguage? setCodeLanguage;
128130
final GetCodeLanguage? getCodeLanguage;
129131
final InlineSpan? inlineSpanEnd;
132+
final PillBuilder? pillBuilder;
130133

131134
TextSpan _parseTextNode(
132135
BuildContext context, ParseContext parseContext, dom.Text node) {
@@ -449,7 +452,7 @@ class TextParser extends StatelessWidget {
449452
if (isPill) {
450453
return WidgetSpan(
451454
alignment: PlaceholderAlignment.middle,
452-
child: Pill(
455+
child: pillBuilder?.call(identifier, url, onPillTap, getMxcUrl) ?? Pill(
453456
identifier: identifier,
454457
url: url,
455458
future: getPillInfo?.call(url),

0 commit comments

Comments
 (0)