Skip to content

Commit

Permalink
Add support for android keyboard content insertion (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmarshall committed May 25, 2023
1 parent df3afd3 commit c1bef0a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/src/widgets/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class QuillEditor extends StatefulWidget {
this.enableUnfocusOnTapOutside = true,
this.customLinkPrefixes = const <String>[],
this.dialogTheme,
this.contentInsertionConfiguration,
Key? key,
}) : super(key: key);

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

/// Configuration of handler for media content inserted via the system input method.
///
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
final ContentInsertionConfiguration? contentInsertionConfiguration;

@override
QuillEditorState createState() => QuillEditorState();
}
Expand Down Expand Up @@ -528,6 +534,7 @@ class QuillEditorState extends State<QuillEditor>
customLinkPrefixes: widget.customLinkPrefixes,
enableUnfocusOnTapOutside: widget.enableUnfocusOnTapOutside,
dialogTheme: widget.dialogTheme,
contentInsertionConfiguration: widget.contentInsertionConfiguration,
);

final editor = I18n(
Expand Down
13 changes: 12 additions & 1 deletion lib/src/widgets/raw_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class RawEditor extends StatefulWidget {
this.onImagePaste,
this.customLinkPrefixes = const <String>[],
this.dialogTheme,
this.contentInsertionConfiguration,
}) : 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,
Expand Down Expand Up @@ -270,6 +271,11 @@ class RawEditor extends StatefulWidget {
/// Configures the dialog theme.
final QuillDialogTheme? dialogTheme;

/// Configuration of handler for media content inserted via the system input method.
///
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
final ContentInsertionConfiguration? contentInsertionConfiguration;

@override
State<StatefulWidget> createState() => RawEditorState();
}
Expand Down Expand Up @@ -326,7 +332,12 @@ class RawEditorState extends EditorState
TextDirection get _textDirection => Directionality.of(context);

@override
void insertContent(KeyboardInsertedContent content) {}
void insertContent(KeyboardInsertedContent content) {
assert(widget.contentInsertionConfiguration?.allowedMimeTypes
.contains(content.mimeType) ??
false);
widget.contentInsertionConfiguration?.onContentInserted.call(content);
}

/// Returns the [ContextMenuButtonItem]s representing the buttons in this
/// platform's default selection menu for [RawEditor].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ mixin RawEditorStateTextInputClientMixin on EditorState
enableSuggestions: !widget.readOnly,
keyboardAppearance: widget.keyboardAppearance,
textCapitalization: widget.textCapitalization,
allowedMimeTypes: widget.contentInsertionConfiguration == null
? const <String>[]
: widget.contentInsertionConfiguration!.allowedMimeTypes,
),
);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository: https://github.com/singerdmx/flutter-quill

environment:
sdk: ">=2.17.0 <4.0.0"
flutter: ">=3.0.0"
flutter: ">=3.10.0"

dependencies:
flutter:
Expand Down

0 comments on commit c1bef0a

Please sign in to comment.