Expose ContextMenuBuilder

pull/1323/head
Fabian Daugs 2 years ago
parent 0885d4fd54
commit 0a5c912584
  1. 22
      README.md
  2. 10
      lib/src/widgets/editor.dart

@ -338,6 +338,28 @@ And voila, we have a custom widget inside of the rich text editor!
> 1. For more info and a video example, see the [PR of this feature](https://github.com/singerdmx/flutter-quill/pull/877) > 1. For more info and a video example, see the [PR of this feature](https://github.com/singerdmx/flutter-quill/pull/877)
> 2. For more details, check out [this YouTube video](https://youtu.be/pI5p5j7cfHc) > 2. For more details, check out [this YouTube video](https://youtu.be/pI5p5j7cfHc)
### Custom Context Menu
You can customize the context menu by providing a `contextMenuBuilder` to the `QuillEditor` widget. If you want to keep the default ContextMenueItems, you can use `state.defaultContextMenuItems` and add your own items to it.
```dart
contextMenuBuilder: (BuildContext context, RawEditorState state) {
return TextFieldTapRegion(
child: AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: [
...state.contextMenuButtonItems,
ContextMenuButtonItem(
label: 'Custom Context Menu Action',
onPressed: () {
print(_controller?.getPlainText()); // Print the selected text, by accessing the QuillController
},
),
],
anchors: state.contextMenuAnchors,
),
);
}
```
### Translation ### Translation
The package offers translations for the quill toolbar and editor, it will follow the system locale unless you set your own locale with: The package offers translations for the quill toolbar and editor, it will follow the system locale unless you set your own locale with:

@ -1,5 +1,4 @@
import 'dart:math' as math; import 'dart:math' as math;
// ignore: unnecessary_import // ignore: unnecessary_import
import 'dart:typed_data'; import 'dart:typed_data';
@ -191,6 +190,7 @@ class QuillEditor extends StatefulWidget {
this.customLinkPrefixes = const <String>[], this.customLinkPrefixes = const <String>[],
this.dialogTheme, this.dialogTheme,
this.contentInsertionConfiguration, this.contentInsertionConfiguration,
this.contextMenuBuilder,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -438,6 +438,9 @@ class QuillEditor extends StatefulWidget {
/// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html] /// See [https://api.flutter.dev/flutter/widgets/EditableText/contentInsertionConfiguration.html]
final ContentInsertionConfiguration? contentInsertionConfiguration; final ContentInsertionConfiguration? contentInsertionConfiguration;
/// Builds the text selection toolbar when requested by the user.
final Widget Function(BuildContext, RawEditorState)? contextMenuBuilder;
@override @override
QuillEditorState createState() => QuillEditorState(); QuillEditorState createState() => QuillEditorState();
} }
@ -503,8 +506,9 @@ class QuillEditorState extends State<QuillEditor>
readOnly: widget.readOnly, readOnly: widget.readOnly,
placeholder: widget.placeholder, placeholder: widget.placeholder,
onLaunchUrl: widget.onLaunchUrl, onLaunchUrl: widget.onLaunchUrl,
contextMenuBuilder: contextMenuBuilder: showSelectionToolbar
showSelectionToolbar ? RawEditor.defaultContextMenuBuilder : null, ? widget.contextMenuBuilder ?? RawEditor.defaultContextMenuBuilder
: null,
showSelectionHandles: isMobile(theme.platform), showSelectionHandles: isMobile(theme.platform),
showCursor: widget.showCursor, showCursor: widget.showCursor,
cursorStyle: CursorStyle( cursorStyle: CursorStyle(

Loading…
Cancel
Save