Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ Once the above issue is resolved, the aforementioned compromises will go away. C
| `style` | A powerful API that allows you to customize the style that should be used when rendering a specific HTMl tag. |
| `navigationDelegateForIframe` | Allows you to set the `NavigationDelegate` for the `WebView`s of all the iframes rendered by the `Html` widget. |
| `customImageRender` | A powerful API that allows you to fully customize how images are loaded. |
| `selectionControls` | A custom text selection controls that allow you to override default toolbar and build toolbar with custom text selection options. See an [example](https://github.com/justinmc/flutter-text-selection-menu-examples/blob/master/lib/custom_menu_page.dart). |

### Getters:

Expand Down
7 changes: 7 additions & 0 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class SelectableHtml extends StatelessWidget {
this.shrinkWrap = false,
this.style = const {},
this.tagsList = const [],
this.selectionControls
}) : document = null,
assert(data != null),
_anchorKey = anchorKey ?? GlobalKey(),
Expand All @@ -236,6 +237,7 @@ class SelectableHtml extends StatelessWidget {
this.shrinkWrap = false,
this.style = const {},
this.tagsList = const [],
this.selectionControls
}) : data = null,
assert(document != null),
_anchorKey = anchorKey ?? GlobalKey(),
Expand Down Expand Up @@ -270,6 +272,10 @@ class SelectableHtml extends StatelessWidget {
/// An API that allows you to override the default style for any HTML element
final Map<String, Style> style;

/// Custom Selection controls allows you to override default toolbar and build custom toolbar
/// options
final TextSelectionControls? selectionControls;

static List<String> get tags => new List<String>.from(SELECTABLE_ELEMENTS);

@override
Expand All @@ -295,6 +301,7 @@ class SelectableHtml extends StatelessWidget {
imageRenders: defaultImageRenders,
tagsList: tagsList.isEmpty ? SelectableHtml.tags : tagsList,
navigationDelegateForIframe: null,
selectionControls: selectionControls,
),
);
}
Expand Down
7 changes: 7 additions & 0 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class HtmlParser extends StatelessWidget {
final List<String> tagsList;
final NavigationDelegate? navigationDelegateForIframe;
final OnTap? _onAnchorTap;
final TextSelectionControls? selectionControls;

HtmlParser({
required this.key,
Expand All @@ -75,6 +76,7 @@ class HtmlParser extends StatelessWidget {
required this.imageRenders,
required this.tagsList,
required this.navigationDelegateForIframe,
this.selectionControls
}) : this._onAnchorTap = onAnchorTap != null
? onAnchorTap
: key != null
Expand Down Expand Up @@ -125,6 +127,7 @@ class HtmlParser extends StatelessWidget {
tree: cleanedTree,
style: cleanedTree.style,
),
selectionControls: selectionControls,
);
}
return StyledText(
Expand Down Expand Up @@ -1052,13 +1055,15 @@ class StyledText extends StatelessWidget {
final RenderContext renderContext;
final AnchorKey? key;
final bool _selectable;
final TextSelectionControls? selectionControls;

const StyledText({
required this.textSpan,
required this.style,
this.textScaleFactor = 1.0,
required this.renderContext,
this.key,
this.selectionControls,
}) : _selectable = false,
super(key: key);

Expand All @@ -1068,6 +1073,7 @@ class StyledText extends StatelessWidget {
this.textScaleFactor = 1.0,
required this.renderContext,
this.key,
this.selectionControls
}) : textSpan = textSpan,
_selectable = true,
super(key: key);
Expand All @@ -1082,6 +1088,7 @@ class StyledText extends StatelessWidget {
textDirection: style.direction,
textScaleFactor: textScaleFactor,
maxLines: style.maxLines,
selectionControls: selectionControls,
);
}
return SizedBox(
Expand Down