0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Flutter】iOSでWebviewの長押しによるプレビュー表示を無効化する方法

Last updated at Posted at 2025-08-08

はじめに

iOSでWebviewを表示してる時に、リンクを長押しするとプレビューリンクのポップアップが表示されます。

Webviewで長押しによるメニュー表示の制御を紹介します。

プレビューリンク有効 プレビューリンク無効
before-preview1.gif after-preview1.gif

プレビューリンクを無効化する方法

allowsLinkPreview を使用します。

iOS 10以降では、デフォルトでtrueとなっているので、 allowsLinkPreview = false とすればOKです。

以下はwebviewのパッケージであるflutter_inappwebviewwebview_flutterでの設定方法です。

flutter_inappwebviewの場合

  • flutter_inappwebview: ^6.1.5

プロパティであるallowsLinkPreviewをfalseにするだけでOK

allowsLinkPreview: false,

webview_flutterの場合

公式がサポートしてるwebview_flutterでも無効化できました。

  • webview_flutter: ^4.13.0

To access platform-specific features, start by adding the platform implementation packages to your app or package:

プラットフォーム固有の機能はwebview_flutter_wkwebviewを追加してねとありました。

  • webview_flutter_wkwebview: ^3.23.0

公式にならって書いてみました。他にもいい書き方があれば指摘お願いします🙇‍♂️

    final controller = WebViewController()
      ..loadRequest(Uri.parse('https://flutter.dev'));

    if (WebViewPlatform.instance is WebKitWebViewPlatform) {
      (controller.platform as WebKitWebViewController).setAllowsLinkPreview(
        false,
      );
    }

リンクプレビューってそもそも何?

リンクプレビューは、iOSの「触覚タッチ(Haptic Touch)」によって提供される、リンク先を手軽に"チラ見"できる機能です。

ユーザーがWebView上のリンクを長押しすると、ページ全体を読み込むことなく、ポップアップでリンク先のコンテンツをプレビューできます。

便利な機能ですが、意図せずOS標準のプレビューが表示されるのを防ぎたいケースで今回の設定が役立ちます。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?