Skip to main content
Version: 5.x.x

Context Menu

ContextMenu represents the WebView's context menu.

Basic Usage

You can customize WebView's context menu adding custom menu items, and/or hiding the default system menu items. For each custom menu item, you can declare a callback action to be invoked when the user clicks on it.

So, the ContextMenu class represents the WebView context menu. It used by WebView.contextMenu or by InAppBrowser.contextMenu.

ContextMenu.menuItems contains the list of the custom ContextMenuItem.

Note for Android

To make it work properly, JavaScript must be enabled.

Note for iOS

To make it work with links, you need to set the allowsLinkPreview iOS-specific WebView option to false.


import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

Future main() async {

if (Platform.isAndroid) {
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);

runApp(MaterialApp(home: new MyApp()));

class MyApp extends StatefulWidget {

_MyAppState createState() => new _MyAppState();

class _MyAppState extends State<MyApp> {
final GlobalKey webViewKey = GlobalKey();

InAppWebViewController? webViewController;
InAppWebViewGroupOptions options = InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
useHybridComposition: true,
late ContextMenu contextMenu;

void initState() {

contextMenu = ContextMenu(
menuItems: [
androidId: 1,
iosId: "1",
title: "Special",
action: () async {
final snackBar = SnackBar(
content: Text("Special clicked!"),
duration: Duration(seconds: 1),
onCreateContextMenu: (hitTestResult) async {
String selectedText =
await webViewController?.getSelectedText() ?? "";
final snackBar = SnackBar(
content: Text(
"Selected text: '$selectedText', of type: ${hitTestResult.type.toString()}"),
duration: Duration(seconds: 1),
onContextMenuActionItemClicked: (menuItem) {
var id = (Platform.isAndroid) ? menuItem.androidId : menuItem.iosId;

final snackBar = SnackBar(
content: Text(
"Menu item with ID $id and title '${menuItem.title}' clicked!"),
duration: Duration(seconds: 1),

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('ContextMenu Example'),
body: Column(children: <Widget>[
child: InAppWebView(
key: webViewKey,
URLRequest(url: Uri.parse("")),
contextMenu: contextMenu,
initialOptions: options,
onWebViewCreated: (InAppWebViewController controller) {
webViewController = controller;

This is the result:

Android context menu basic usage