Custom Context Menu
Since ComPDF Flutter SDK 2.6.0, the SDK supports custom context menu items and provides corresponding click event callback mechanisms to respond to user interaction with custom menu buttons.
For information on how to configure and add custom context menu items, please refer to Context Menu.
Listen to Custom Context Menu Item Click Events
When creating CPDFReaderWidget, you can set the onCustomContextMenuItemTappedCallback callback to listen to custom context menu item click events. For example:
CPDFReaderWidget(
document: documentPath,
configuration: configuration,
onCreated: (controller) {},
onCustomContextMenuItemTappedCallback: (String identifier, dynamic event) {
debugPrint('Custom context menu item tapped: $identifier');
// Handle custom context menu item click logic here
},
);2
3
4
5
6
7
8
9
Callback Function Explanation
The function signature of onCustomContextMenuItemTappedCallback is as follows:
void Function(String identifier, dynamic event)| Parameter Name | Type | Description |
|---|---|---|
| identifier | String | Unique identifier of the clicked custom menu item. Specified via CPDFContextMenuItem when configuring menu items. |
| event | dynamic | Context data (payload) carried by the click event. Different menu contexts and menu types return different data structures. |
Event Data Structure Explanation
Note: event is usually returned in the form of
Map<String, dynamic>. When the return value contains CPDFAnnotation, CPDFWidget, and other objects, you can further retrieve detailed attribute information through the corresponding object's API.
1) Global
screenshot (Screenshot-related menu)
event = {
"identifier": String,
"image": Uint8List,
};2
3
4
| Field | Type | Description |
|---|---|---|
| identifier | String | Menu item identifier |
| image | Uint8List | Screenshot image data |
2) View Mode
textSelect (Text selection in view mode)
event = {
"identifier": String,
"text": String,
"rect": CPDFRectF,
"pageIndex": int,
};2
3
4
5
6
| Field | Type | Description |
|---|---|---|
| identifier | String | Menu item identifier |
| text | String | Selected text content |
| rect | CPDFRectF | Text selection area on page |
| pageIndex | int | Page index containing the text |
3) Annotation Mode
textSelect (Text selection in annotation mode)
event = {
"identifier": String,
"text": String,
"rect": CPDFRectF,
"pageIndex": int,
};2
3
4
5
6
longPressContent (Long press page content)
event = {
"identifier": String,
"point": CPDFPointF,
"pageIndex": int,
};2
3
4
5
markupContent / soundContent / inkContent / shapeContent / freeTextContent / signStampContent / stampContent / linkContent
When the context menu corresponds to an annotation object (such as highlight, ink, shape, free text, signature/stamp, link, etc.), event will return the corresponding annotation instance:
event = {
"annotation": CPDFAnnotation,
};2
3
4) Content Editor Mode
editTextAreaContent / editSelectTextContent
(Content Editor: Text area / Selected text)
event = {
"editArea": CPDFEditTextArea,
};2
3
imageAreaContent (Content Editor: Image area)
event = {
"imageArea": CPDFEditImageArea,
};2
3
editPathContent (Content Editor: Path / Shape area)
event = {
"editArea": CPDFEditPathArea,
};2
3
longPressWithEditTextMode / longPressWithEditImageMode / longPressWithAllMode
(Long press operations in content editor mode)
event = {
"point": Offset,
"pageIndex": int,
};2
3
4
5) Form Mode
textField / checkBox / radioButton / listBox / comboBox / signatureField / pushButton
(Form mode-related form field menus)
event = {
"widget": CPDFWidget,
};2
3