パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.0.6

pwa_install

モバイルWebユーザーにFlutterアプリをPWAとしてインストールするように促すことができるFlutterパッケージ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3030
いいね数
100
Pub ポイント
140

パッケージをインストール

flutter pub add pwa_install

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

pwa_install パッケージは、Flutter アプリがモバイル Web ユーザーにプログレッシブ Web アプリ(PWA)としてアプリをインストールするよう促すことを可能にします。ユーザーがモバイルデバイス上の Web ブラウザ経由でアプリにアクセスしているかどうかを検出し、ネイティブなインストールプロンプトをトリガーすることで、ユーザーのエンゲージメントとリテンションを向上させます。このパッケージは Flutter の Web プラットフォームとシームレスに統合され、Android、iOS、macOS、Windows、Linux など複数のオペレーティングシステムをサポートしています。ブラウザレベルの PWA 機能を活用して、スムーズなインストール体験を提供します。

用途

  • ウェブユーザーにPWAのインストールを促す
  • モバイルブラウザでのアプリ参加度の向上
  • WebベースのFlutterアプリのリテンション向上
  • PWA を通じたオフラインアクセスの有効化
  • クロスプラットフォームデプロイの簡素化
  • ハイブリッドアプリの配信をサポート

主な機能

  • モバイルWebアクセスを検出します
  • ネイティブなPWAインストールプロンプトをトリガーします
  • 複数のプラットフォームで動作します
  • 最小限のセットアップが必要
  • Flutter Web との統合
  • ブラウザのPWA APIを活用

適している対象

  • Web最優先のFlutterアプリを開発する開発者
  • モバイルウェブユーザーをターゲットにするチーム
  • PWAの採用を目指すアプリ
  • 低抵抗インストールを必要とするプロジェクト
  • クロスプラットフォームWebアプリケーション
  • ハイブリッドアプリ戦略

注意事項

  • PWA 機能には HTTPS が必要です
  • PWAインストールプロンプトをサポートするブラウザに限定
  • すべてのモバイルデバイスでトリガーされない可能性があります
  • ユーザーの権限設定に依存します
  • Web以外のプラットフォームには対応していません
  • インストールの動作はブラウザによって異なります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

PWA Install

A small Flutter package that allows you to prompt mobile web users to install your Flutter app as a progressive web application (PWA) on demand.

A very basic example can be found here: PWA Install

The contents of this package are based on this article by Pete LePage (@petele)

Out-of-the-Box

As of release 1.20, all Flutter apps can be installed as PWAs. Combine this with the fact that all Chromium based browsers support PWAs and it becomes clear that designing your Flutter application for a mobile browser can be the most effective way of reaching a large audience.

When a Flutter app is opened in a supported browser, the user will see an install prompt like this:

Mobile Prompt Web Prompt
img.png img.png

This is awesome, but there's a caveat. The browser will only show the install prompt to users the first time they open your app. If the user refreshes the page or returns to the app while it's still in their browser history, the prompt will not be shown.

The PWA Install Package

With this package, you can prompt the user to install your app as a PWA on demand (e.g, on a button click). This package works by capturing the beforeinstallprompt event web browsers use to install PWAs. The event is captured when your app is launched and can be called anytime thereafter.

Setup

1. Update index.html

Add the following <script> tag to the body of web/index.html:

<!-- Capture PWA install prompt event -->
<script>
    let deferredPrompt;

    window.addEventListener('beforeinstallprompt', (e) => {
      deferredPrompt = e;
    });

    function promptInstall(){
       deferredPrompt.prompt();
    }

    // Listen for app install event
    window.addEventListener('appinstalled', () => {
      deferredPrompt = null;
      appInstalled();
    });

    // Track how PWA was launched (either from browser or as PWA)
    function getLaunchMode() {
      const isStandalone = window.matchMedia('(display-mode: standalone)').matches;
      if(deferredPrompt) hasPrompt();
      if (document.referrer.startsWith('android-app://')) {
        appLaunchedAsTWA();
      } else if (navigator.standalone || isStandalone) {
        appLaunchedAsPWA();
      } else {
        window.appLaunchedInBrowser();
      }
    }
</script>

2. Call PWAInstall().setup()

The following method can be called in main.dart before calling runApp(). PWAInstall() is instantiated as a singleton so you can use the class directly.

Future<void> main() async {

  // Add this
  PWAInstall().setup(installCallback: () {
    debugPrint('APP INSTALLED!');
  });

  runApp(MaterialApp(home: App()));
}

3. Check if the Install Prompt is enabled

Before calling the promptInstall_() method, you can check if the Install Prompt is available using PWAInstall().installPromptEnabled.

installPromptEnabled will be true if:

  • [x] The app was launched in a browser (It doesn't make sense to prompt a PWA install if the app is already running as a PWA)
  • [x] The beforeinstallprompt event was captured.

promptInstall_() won't do anything if installPromptEnabled is false so you should check this flag before attempting to call the prompt.

4. Call PWAInstall().promptInstall_()

Finally, call PWAInstall().promptInstall_() to show the install prompt.

Prompt Config

App Name

You can change the app name that's displayed in the prompt by updating the "name" field in web/manifest.json.

img.png

App Logo

The logo displayed in the prompt also comes from the web/manifest.json file.

  1. (Optional) Use a website like favicon.io to generate your web icons
  2. Add your logos to the web/icons folder

img.png

  1. Add the following lines to the tag in index.html:
<link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png">

img.png

Screenshots

In addition to the name and logo, you can also add optional screenshots to the manifest.json file.

"screenshots": [{
    "src": "images/app_screenshot.webp",
    "platform": "windows",
    "label": "PWA is the way!"
  }],

Note that the screenshots will not appear in every browser. After they are added, your new install prompt will look like this: images

Troubleshooting

Supported Browsers

You can find all supported browsers here.

Support

Buy Me A Coffee

Keep My Lights On

:heart: Sponsor on GitHub

カテゴリー

依存関係

依存関係一覧 1 件

  • js^0.7.1

ソースリポジトリ

このパッケージを使用しているプロジェクト