Skip to content

Commit 7e2d4af

Browse files
authored
Merge pull request Sub6Resources#809 from kirankumbhar/selection-controls
Feature: Added selectionControls property to selectableHtml
2 parents e713e3e + 5a2980a commit 7e2d4af

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ Once the above issue is resolved, the aforementioned compromises will go away. C
185185
| `style` | A powerful API that allows you to customize the style that should be used when rendering a specific HTMl tag. |
186186
| `navigationDelegateForIframe` | Allows you to set the `NavigationDelegate` for the `WebView`s of all the iframes rendered by the `Html` widget. |
187187
| `customImageRender` | A powerful API that allows you to fully customize how images are loaded. |
188+
| `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). |
188189

189190
### Getters:
190191

lib/flutter_html.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ class SelectableHtml extends StatelessWidget {
221221
this.shrinkWrap = false,
222222
this.style = const {},
223223
this.tagsList = const [],
224+
this.selectionControls
224225
}) : document = null,
225226
assert(data != null),
226227
_anchorKey = anchorKey ?? GlobalKey(),
@@ -236,6 +237,7 @@ class SelectableHtml extends StatelessWidget {
236237
this.shrinkWrap = false,
237238
this.style = const {},
238239
this.tagsList = const [],
240+
this.selectionControls
239241
}) : data = null,
240242
assert(document != null),
241243
_anchorKey = anchorKey ?? GlobalKey(),
@@ -270,6 +272,10 @@ class SelectableHtml extends StatelessWidget {
270272
/// An API that allows you to override the default style for any HTML element
271273
final Map<String, Style> style;
272274

275+
/// Custom Selection controls allows you to override default toolbar and build custom toolbar
276+
/// options
277+
final TextSelectionControls? selectionControls;
278+
273279
static List<String> get tags => new List<String>.from(SELECTABLE_ELEMENTS);
274280

275281
@override
@@ -295,6 +301,7 @@ class SelectableHtml extends StatelessWidget {
295301
imageRenders: defaultImageRenders,
296302
tagsList: tagsList.isEmpty ? SelectableHtml.tags : tagsList,
297303
navigationDelegateForIframe: null,
304+
selectionControls: selectionControls,
298305
),
299306
);
300307
}

lib/html_parser.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class HtmlParser extends StatelessWidget {
5858
final List<String> tagsList;
5959
final NavigationDelegate? navigationDelegateForIframe;
6060
final OnTap? _onAnchorTap;
61+
final TextSelectionControls? selectionControls;
6162

6263
HtmlParser({
6364
required this.key,
@@ -75,6 +76,7 @@ class HtmlParser extends StatelessWidget {
7576
required this.imageRenders,
7677
required this.tagsList,
7778
required this.navigationDelegateForIframe,
79+
this.selectionControls
7880
}) : this._onAnchorTap = onAnchorTap != null
7981
? onAnchorTap
8082
: key != null
@@ -125,6 +127,7 @@ class HtmlParser extends StatelessWidget {
125127
tree: cleanedTree,
126128
style: cleanedTree.style,
127129
),
130+
selectionControls: selectionControls,
128131
);
129132
}
130133
return StyledText(
@@ -1052,13 +1055,15 @@ class StyledText extends StatelessWidget {
10521055
final RenderContext renderContext;
10531056
final AnchorKey? key;
10541057
final bool _selectable;
1058+
final TextSelectionControls? selectionControls;
10551059

10561060
const StyledText({
10571061
required this.textSpan,
10581062
required this.style,
10591063
this.textScaleFactor = 1.0,
10601064
required this.renderContext,
10611065
this.key,
1066+
this.selectionControls,
10621067
}) : _selectable = false,
10631068
super(key: key);
10641069

@@ -1068,6 +1073,7 @@ class StyledText extends StatelessWidget {
10681073
this.textScaleFactor = 1.0,
10691074
required this.renderContext,
10701075
this.key,
1076+
this.selectionControls
10711077
}) : textSpan = textSpan,
10721078
_selectable = true,
10731079
super(key: key);
@@ -1082,6 +1088,7 @@ class StyledText extends StatelessWidget {
10821088
textDirection: style.direction,
10831089
textScaleFactor: textScaleFactor,
10841090
maxLines: style.maxLines,
1091+
selectionControls: selectionControls,
10851092
);
10861093
}
10871094
return SizedBox(

0 commit comments

Comments
 (0)