From bcc9ff1e67c6129ab8bbf2cd38ce64fa8cd99c64 Mon Sep 17 00:00:00 2001 From: dylan-kwon Date: Fri, 15 Sep 2023 15:32:34 +0900 Subject: [PATCH] Expose navigationDelegate. --- lib/src/quill_editor_wrapper.dart | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/src/quill_editor_wrapper.dart b/lib/src/quill_editor_wrapper.dart index 16b251b..7ba4f99 100644 --- a/lib/src/quill_editor_wrapper.dart +++ b/lib/src/quill_editor_wrapper.dart @@ -55,6 +55,7 @@ class QuillHtmlEditor extends StatefulWidget { color: Colors.black87, fontWeight: FontWeight.normal, ), + this.navigationDelegate, }) : super(key: controller._editorKey); /// [text] to set initial text to the editor, please use text @@ -153,6 +154,10 @@ class QuillHtmlEditor extends StatefulWidget { /// **Note** due to limitations of flutter webview at the moment, focus doesn't launch the keyboard in mobile, however, it will set the cursor at the end on focus. final bool? autoFocus; + /// Callback to decide whether to allow navigation to the incoming url + final FutureOr Function(NavigationRequest navigation)? + navigationDelegate; + @override QuillHtmlEditorState createState() => QuillHtmlEditorState(); } @@ -176,6 +181,7 @@ class QuillHtmlEditorState extends State { late String _fontFamily; late String _encodedStyle; bool _editorLoaded = false; + @override initState() { _loadScripts = rootBundle.loadString( @@ -412,6 +418,18 @@ class QuillHtmlEditorState extends State { mobileSpecificParams: const MobileSpecificParams( androidEnableHybridComposition: true, ), + navigationDelegate: widget.navigationDelegate == null + ? null + : (navigation) async { + final consumed = + await widget.navigationDelegate?.call(navigation) ?? + false; + if (consumed) { + return NavigationDecision.prevent; + } else { + return NavigationDecision.navigate; + } + }, ), Visibility( visible: !_editorLoaded,