Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ migrate_working_dir/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/pubspec.lock
**/doc/api/
.dart_tool/
build/
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.4"
version: "1.1.5"
http:
dependency: transitive
description:
Expand Down
30 changes: 30 additions & 0 deletions lib/custom_widgets/markdown_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ typedef HighlightBuilder =
/// A builder function for the image.
typedef ImageBuilder = Widget Function(BuildContext context, String imageUrl);

/// A builder function for the checkbox.
typedef CheckBoxBuilder =
Widget Function(
BuildContext context,
bool isChecked,
Widget child,
GptMarkdownConfig config,
);

/// A builder function for the radio button.
typedef RadioButtonBuilder =
Widget Function(
BuildContext context,
bool isSelected,
Widget child,
GptMarkdownConfig config,
);

/// A configuration class for the GPT Markdown component.
///
/// The [GptMarkdownConfig] class is used to configure the GPT Markdown component.
Expand Down Expand Up @@ -93,6 +111,8 @@ class GptMarkdownConfig {
this.components,
this.inlineComponents,
this.tableBuilder,
this.checkBoxBuilder,
this.radioButtonBuilder,
});

/// The direction of the text.
Expand Down Expand Up @@ -155,6 +175,12 @@ class GptMarkdownConfig {
/// The table builder.
final TableBuilder? tableBuilder;

/// The checkbox builder.
final CheckBoxBuilder? checkBoxBuilder;

/// The radio button builder.
final RadioButtonBuilder? radioButtonBuilder;

/// A copy of the configuration with the specified parameters.
GptMarkdownConfig copyWith({
TextStyle? style,
Expand All @@ -177,6 +203,8 @@ class GptMarkdownConfig {
final List<MarkdownComponent>? components,
final List<MarkdownComponent>? inlineComponents,
final TableBuilder? tableBuilder,
final CheckBoxBuilder? checkBoxBuilder,
final RadioButtonBuilder? radioButtonBuilder,
}) {
return GptMarkdownConfig(
style: style ?? this.style,
Expand All @@ -199,6 +227,8 @@ class GptMarkdownConfig {
components: components ?? this.components,
inlineComponents: inlineComponents ?? this.inlineComponents,
tableBuilder: tableBuilder ?? this.tableBuilder,
checkBoxBuilder: checkBoxBuilder ?? this.checkBoxBuilder,
radioButtonBuilder: radioButtonBuilder ?? this.radioButtonBuilder,
);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/gpt_markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class GptMarkdown extends StatelessWidget {
this.components,
this.inlineComponents,
this.useDollarSignsForLatex = false,
this.checkBoxBuilder,
this.radioButtonBuilder,
});

/// The direction of the text.
Expand Down Expand Up @@ -104,6 +106,12 @@ class GptMarkdown extends StatelessWidget {
/// The table builder.
final TableBuilder? tableBuilder;

/// The checkbox builder.
final CheckBoxBuilder? checkBoxBuilder;

/// The radio button builder.
final RadioButtonBuilder? radioButtonBuilder;

/// The list of components.
/// ```dart
/// List<MarkdownComponent> components = [
Expand Down Expand Up @@ -207,6 +215,8 @@ class GptMarkdown extends StatelessWidget {
components: components,
inlineComponents: inlineComponents,
tableBuilder: tableBuilder,
checkBoxBuilder: checkBoxBuilder,
radioButtonBuilder: radioButtonBuilder,
),
),
);
Expand Down
29 changes: 19 additions & 10 deletions lib/markdown_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,15 @@ class CheckBoxMd extends BlockMd {
final GptMarkdownConfig config,
) {
var match = this.exp.firstMatch(text.trim());
return CustomCb(
value: ("${match?[1]}" == "x"),
textDirection: config.textDirection,
child: MdWidget(context, "${match?[2]}", false, config: config),
);
var isChecked = ("${match?[1]}" == "x");
var child = MdWidget(context, "${match?[2]}", false, config: config);

return config.checkBoxBuilder?.call(context, isChecked, child, config) ??
CustomCb(
value: isChecked,
textDirection: config.textDirection,
child: child,
);
}
}

Expand All @@ -312,11 +316,16 @@ class RadioButtonMd extends BlockMd {
final GptMarkdownConfig config,
) {
var match = this.exp.firstMatch(text.trim());
return CustomRb(
value: ("${match?[1]}" == "x"),
textDirection: config.textDirection,
child: MdWidget(context, "${match?[2]}", false, config: config),
);
var isSelected = ("${match?[1]}" == "x");
var child = MdWidget(context, "${match?[2]}", false, config: config);

return config.radioButtonBuilder
?.call(context, isSelected, child, config) ??
CustomRb(
value: isSelected,
textDirection: config.textDirection,
child: child,
);
}
}

Expand Down
Loading