Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expose navigation delegate #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions lib/src/quill_editor_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<bool> Function(NavigationRequest navigation)?
navigationDelegate;

@override
QuillHtmlEditorState createState() => QuillHtmlEditorState();
}
Expand All @@ -176,6 +181,7 @@ class QuillHtmlEditorState extends State<QuillHtmlEditor> {
late String _fontFamily;
late String _encodedStyle;
bool _editorLoaded = false;

@override
initState() {
_loadScripts = rootBundle.loadString(
Expand Down Expand Up @@ -412,6 +418,18 @@ class QuillHtmlEditorState extends State<QuillHtmlEditor> {
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,
Expand Down