Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve/add pill builder for customization #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -461,7 +464,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