pwa_install 包使 Flutter 应用能够提示移动网页用户将他们的应用安装为渐进式 Web 应用(PWA)。它检测用户是否通过移动设备上的网页浏览器访问应用,并触发原生安装提示,从而提高用户参与度和留存率。该包与 Flutter 的 Web 平台无缝集成,支持多种操作系统,包括 Android、iOS、macOS、Windows 和 Linux。它利用浏览器级别的 PWA 功能,提供流畅的安装体验。
适合场景
提示网络用户安装PWA
提高移动浏览器上的应用参与度
改进基于 Web 的 Flutter 应用的留存率
通过 PWA 启用离线访问
简化跨平台部署
支持混合应用分发
主要特点
检测移动网页访问
触发原生 PWA 安装提示
跨多个平台运行
所需设置最少
与 Flutter Web 集成
利用浏览器 PWA API
适合对象
开发面向网络的 Flutter 应用程序的开发者
针对移动网页用户的团队
旨在采用 PWA 的应用
需要低摩擦安装的项目
跨平台网页应用
混合应用策略
使用建议
PWA 功能需要 HTTPS
仅限支持 PWA 安装提示的浏览器
可能不会在所有移动设备上触发
取决于用户权限设置
不适用于非网页平台
安装行为因浏览器而异
原始 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
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:
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.