2020-05-21 01:34:39 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter_inappwebview/src/webview.dart';
|
|
|
|
|
|
|
|
import 'types.dart';
|
|
|
|
|
|
|
|
///Class that represents the WebView context menu. It used by [WebView.contextMenu].
|
|
|
|
///
|
|
|
|
///**NOTE**: To make it work properly on Android, JavaScript should be enabled!
|
|
|
|
class ContextMenu {
|
|
|
|
///Event fired when the context menu for this WebView is being built.
|
|
|
|
///
|
|
|
|
///[hitTestResult] represents the hit result for hitting an HTML elements.
|
2020-05-29 17:56:03 +00:00
|
|
|
final void Function(InAppWebViewHitTestResult hitTestResult)
|
|
|
|
onCreateContextMenu;
|
2020-05-21 01:34:39 +00:00
|
|
|
|
|
|
|
///Event fired when the context menu for this WebView is being hidden.
|
|
|
|
final void Function() onHideContextMenu;
|
|
|
|
|
|
|
|
///Event fired when a context menu item has been clicked.
|
|
|
|
///
|
|
|
|
///[contextMenuItemClicked] represents the [ContextMenuItem] clicked.
|
2020-05-29 17:56:03 +00:00
|
|
|
final void Function(ContextMenuItem contextMenuItemClicked)
|
|
|
|
onContextMenuActionItemClicked;
|
2020-05-21 01:34:39 +00:00
|
|
|
|
|
|
|
///List of the custom [ContextMenuItem].
|
|
|
|
List<ContextMenuItem> menuItems = List();
|
|
|
|
|
2020-05-29 17:56:03 +00:00
|
|
|
ContextMenu(
|
|
|
|
{this.menuItems,
|
|
|
|
this.onCreateContextMenu,
|
|
|
|
this.onHideContextMenu,
|
|
|
|
this.onContextMenuActionItemClicked});
|
2020-05-21 01:34:39 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
"menuItems": menuItems.map((menuItem) => menuItem?.toMap()).toList()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return this.toMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///Class that represent an item of the [ContextMenu].
|
|
|
|
class ContextMenuItem {
|
|
|
|
///Android menu item ID.
|
|
|
|
int androidId;
|
2020-05-29 17:56:03 +00:00
|
|
|
|
2020-05-21 01:34:39 +00:00
|
|
|
///iOS menu item ID.
|
|
|
|
String iosId;
|
2020-05-29 17:56:03 +00:00
|
|
|
|
2020-05-21 01:34:39 +00:00
|
|
|
///Menu item title.
|
|
|
|
String title;
|
2020-05-29 17:56:03 +00:00
|
|
|
|
2020-05-21 01:34:39 +00:00
|
|
|
///Menu item action that will be called when an user clicks on it.
|
|
|
|
Function() action;
|
|
|
|
|
2020-05-29 17:56:03 +00:00
|
|
|
ContextMenuItem(
|
|
|
|
{@required this.androidId,
|
|
|
|
@required this.iosId,
|
|
|
|
@required this.title,
|
|
|
|
this.action});
|
2020-05-21 01:34:39 +00:00
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2020-05-29 17:56:03 +00:00
|
|
|
return {"androidId": androidId, "iosId": iosId, "title": title};
|
2020-05-21 01:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return this.toMap();
|
|
|
|
}
|
|
|
|
}
|