customLinkPrefixes parameter - makes possible to open links with custom protocol (deeplinks) (#1164)

pull/1167/head
spChief 2 years ago committed by GitHub
parent 871b05e237
commit 01271b0cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      lib/src/widgets/editor.dart
  2. 8
      lib/src/widgets/raw_editor.dart
  3. 3
      lib/src/widgets/text_block.dart
  4. 4
      lib/src/widgets/text_line.dart

@ -182,6 +182,7 @@ class QuillEditor extends StatefulWidget {
this.customShortcuts,
this.customActions,
this.detectWordBoundary = true,
this.customLinkPrefixes = const <String>[],
Key? key})
: super(key: key);
@ -401,6 +402,12 @@ class QuillEditor extends StatefulWidget {
final bool detectWordBoundary;
/// Additional list if links prefixes, which must not be prepended
/// with "https://" when [LinkMenuAction.launch] happened
///
/// Useful for deeplinks
final List<String> customLinkPrefixes;
@override
QuillEditorState createState() => QuillEditorState();
}
@ -498,6 +505,7 @@ class QuillEditorState extends State<QuillEditor>
onImagePaste: widget.onImagePaste,
customShortcuts: widget.customShortcuts,
customActions: widget.customActions,
customLinkPrefixes: widget.customLinkPrefixes,
);
final editor = I18n(

@ -78,7 +78,8 @@ class RawEditor extends StatefulWidget {
this.linkActionPickerDelegate = defaultLinkActionPickerDelegate,
this.customStyleBuilder,
this.floatingCursorDisabled = false,
this.onImagePaste})
this.onImagePaste,
this.customLinkPrefixes = const <String>[]})
: assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
@ -250,6 +251,7 @@ class RawEditor extends StatefulWidget {
final LinkActionPickerDelegate linkActionPickerDelegate;
final CustomStyleBuilder? customStyleBuilder;
final bool floatingCursorDisabled;
final List<String> customLinkPrefixes;
@override
State<StatefulWidget> createState() => RawEditorState();
@ -800,7 +802,8 @@ class RawEditorState extends EditorState
clearIndents: clearIndents,
onCheckboxTap: _handleCheckboxTap,
readOnly: widget.readOnly,
customStyleBuilder: widget.customStyleBuilder);
customStyleBuilder: widget.customStyleBuilder,
customLinkPrefixes: widget.customLinkPrefixes);
result.add(Directionality(
textDirection: getDirectionOfNode(node), child: editableTextBlock));
@ -824,6 +827,7 @@ class RawEditorState extends EditorState
controller: controller,
linkActionPicker: _linkActionPicker,
onLaunchUrl: widget.onLaunchUrl,
customLinkPrefixes: widget.customLinkPrefixes,
);
final editableTextLine = EditableTextLine(
node,

@ -73,6 +73,7 @@ class EditableTextBlock extends StatelessWidget {
required this.readOnly,
this.onLaunchUrl,
this.customStyleBuilder,
this.customLinkPrefixes = const <String>[],
Key? key});
final Block block;
@ -95,6 +96,7 @@ class EditableTextBlock extends StatelessWidget {
final bool clearIndents;
final Function(int, bool) onCheckboxTap;
final bool readOnly;
final List<String> customLinkPrefixes;
@override
Widget build(BuildContext context) {
@ -148,6 +150,7 @@ class EditableTextBlock extends StatelessWidget {
controller: controller,
linkActionPicker: linkActionPicker,
onLaunchUrl: onLaunchUrl,
customLinkPrefixes: customLinkPrefixes,
),
_getIndentWidth(),
_getSpacingForLine(line, index, count, defaultStyles),

@ -41,6 +41,7 @@ class TextLine extends StatefulWidget {
required this.linkActionPicker,
this.textDirection,
this.customStyleBuilder,
this.customLinkPrefixes = const <String>[],
Key? key,
}) : super(key: key);
@ -53,6 +54,7 @@ class TextLine extends StatefulWidget {
final CustomStyleBuilder? customStyleBuilder;
final ValueChanged<String>? onLaunchUrl;
final LinkActionPicker linkActionPicker;
final List<String> customLinkPrefixes;
@override
State<TextLine> createState() => _TextLineState();
@ -430,7 +432,7 @@ class _TextLineState extends State<TextLine> {
launchUrl ??= _launchUrl;
link = link.trim();
if (!linkPrefixes
if (!(widget.customLinkPrefixes + linkPrefixes)
.any((linkPrefix) => link!.toLowerCase().startsWith(linkPrefix))) {
link = 'https://$link';
}

Loading…
Cancel
Save