Skip to content

Commit

Permalink
improve/add pill builder for customization
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn committed Jul 3, 2023
1 parent a2e83b9 commit 831af80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Html extends StatelessWidget {
this.getCodeLanguage,
this.setCodeLanguage,
this.inlineSpanEnd,
this.pillBuilder,
}) : super(key: key);

final String data;
Expand All @@ -57,6 +58,7 @@ class Html extends StatelessWidget {
/// Setting and getting code langauge cache
final SetCodeLanguage? setCodeLanguage;
final GetCodeLanguage? getCodeLanguage;
final PillBuilder? pillBuilder;

final InlineSpan? inlineSpanEnd;

Expand Down Expand Up @@ -89,6 +91,7 @@ class Html extends StatelessWidget {
setCodeLanguage: setCodeLanguage,
getCodeLanguage: getCodeLanguage,
inlineSpanEnd: inlineSpanEnd,
pillBuilder: pillBuilder,
),
),
);
Expand Down
5 changes: 4 additions & 1 deletion lib/text_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef OnPillTap = void Function(String identifier);
typedef GetMxcUrl = String Function(String mxc, double? width, double? height,
{bool? animated});
typedef GetPillInfo = Future<Map<String, dynamic>> Function(String identifier);
typedef PillBuilder = Widget? Function(String identifier, String url, OnPillTap? onTap, GetMxcUrl? getMxcUrl);

const OFFSET_TAGS_FONT_SIZE_FACTOR =
0.7; //The ratio of the parent font for each of the offset tags: sup or sub
Expand Down Expand Up @@ -105,6 +106,7 @@ class TextParser extends StatelessWidget {
this.setCodeLanguage,
this.getCodeLanguage,
this.inlineSpanEnd,
this.pillBuilder,
});

final double indentSize = 10.0;
Expand All @@ -127,6 +129,7 @@ class TextParser extends StatelessWidget {
final SetCodeLanguage? setCodeLanguage;
final GetCodeLanguage? getCodeLanguage;
final InlineSpan? inlineSpanEnd;
final PillBuilder? pillBuilder;

TextSpan _parseTextNode(
BuildContext context, ParseContext parseContext, dom.Text node) {
Expand Down Expand Up @@ -449,7 +452,7 @@ class TextParser extends StatelessWidget {
if (isPill) {
return WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: Pill(
child: pillBuilder?.call(identifier, url, onPillTap, getMxcUrl) ?? Pill(
identifier: identifier,
url: url,
future: getPillInfo?.call(url),
Expand Down

0 comments on commit 831af80

Please sign in to comment.