Skip to content

Commit c1bef0a

Browse files
Add support for android keyboard content insertion (singerdmx#1236)
1 parent df3afd3 commit c1bef0a

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

lib/src/widgets/editor.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class QuillEditor extends StatefulWidget {
187187
this.enableUnfocusOnTapOutside = true,
188188
this.customLinkPrefixes = const <String>[],
189189
this.dialogTheme,
190+
this.contentInsertionConfiguration,
190191
Key? key,
191192
}) : super(key: key);
192193

@@ -427,6 +428,11 @@ class QuillEditor extends StatefulWidget {
427428
/// Configures the dialog theme.
428429
final QuillDialogTheme? dialogTheme;
429430

431+
/// Configuration of handler for media content inserted via the system input method.
432+
///
433+
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
434+
final ContentInsertionConfiguration? contentInsertionConfiguration;
435+
430436
@override
431437
QuillEditorState createState() => QuillEditorState();
432438
}
@@ -528,6 +534,7 @@ class QuillEditorState extends State<QuillEditor>
528534
customLinkPrefixes: widget.customLinkPrefixes,
529535
enableUnfocusOnTapOutside: widget.enableUnfocusOnTapOutside,
530536
dialogTheme: widget.dialogTheme,
537+
contentInsertionConfiguration: widget.contentInsertionConfiguration,
531538
);
532539

533540
final editor = I18n(

lib/src/widgets/raw_editor.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class RawEditor extends StatefulWidget {
8484
this.onImagePaste,
8585
this.customLinkPrefixes = const <String>[],
8686
this.dialogTheme,
87+
this.contentInsertionConfiguration,
8788
}) : assert(maxHeight == null || maxHeight > 0, 'maxHeight cannot be null'),
8889
assert(minHeight == null || minHeight >= 0, 'minHeight cannot be null'),
8990
assert(maxHeight == null || minHeight == null || maxHeight >= minHeight,
@@ -270,6 +271,11 @@ class RawEditor extends StatefulWidget {
270271
/// Configures the dialog theme.
271272
final QuillDialogTheme? dialogTheme;
272273

274+
/// Configuration of handler for media content inserted via the system input method.
275+
///
276+
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
277+
final ContentInsertionConfiguration? contentInsertionConfiguration;
278+
273279
@override
274280
State<StatefulWidget> createState() => RawEditorState();
275281
}
@@ -326,7 +332,12 @@ class RawEditorState extends EditorState
326332
TextDirection get _textDirection => Directionality.of(context);
327333

328334
@override
329-
void insertContent(KeyboardInsertedContent content) {}
335+
void insertContent(KeyboardInsertedContent content) {
336+
assert(widget.contentInsertionConfiguration?.allowedMimeTypes
337+
.contains(content.mimeType) ??
338+
false);
339+
widget.contentInsertionConfiguration?.onContentInserted.call(content);
340+
}
330341

331342
/// Returns the [ContextMenuButtonItem]s representing the buttons in this
332343
/// platform's default selection menu for [RawEditor].

lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ mixin RawEditorStateTextInputClientMixin on EditorState
5959
enableSuggestions: !widget.readOnly,
6060
keyboardAppearance: widget.keyboardAppearance,
6161
textCapitalization: widget.textCapitalization,
62+
allowedMimeTypes: widget.contentInsertionConfiguration == null
63+
? const <String>[]
64+
: widget.contentInsertionConfiguration!.allowedMimeTypes,
6265
),
6366
);
6467

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repository: https://github.com/singerdmx/flutter-quill
77

88
environment:
99
sdk: ">=2.17.0 <4.0.0"
10-
flutter: ">=3.0.0"
10+
flutter: ">=3.10.0"
1111

1212
dependencies:
1313
flutter:

0 commit comments

Comments
 (0)