패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.6

pwa_install

모바일 웹 사용자에게 Flutter 앱을 PWA로 설치하도록 유도할 수 있는 Flutter 패키지

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3천
좋아요
100
Pub 점수
140

패키지 설치

flutter pub add pwa_install

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

pwa_install 패키지는 Flutter 애플리케이션에서 모바일 웹 사용자에게 프로그레시브 웹 앱(PWA)으로 앱을 설치하도록 유도할 수 있도록 합니다. 이 패키지는 사용자가 모바일 기기의 웹 브라우저를 통해 앱에 접근하고 있는지 감지하고, 네이티브 설치 프롬프트를 트리거하여 사용자 참여도와 유지율을 향상시킵니다. 이 패키지는 Flutter의 웹 플랫폼과 원활하게 통합되며, 안드로이드, iOS, macOS, Windows, 리눅스 등 여러 운영 체제를 지원합니다. 브라우저 수준의 PWA 기능을 활용하여 부드러운 설치 경험을 제공합니다.

사용 사례

  • 웹 사용자에게 PWA 설치를 유도하기
  • 모바일 브라우저에서 앱 참여도 증가
  • 웹 기반의 Flutter 앱에 대한 유지율 향상
  • PWA를 통한 오프라인 액세스 활성화
  • 크로스 플랫폼 배포 간소화
  • 하이브리드 앱 배포 지원

주요 기능

  • 모바일 웹 액세스를 감지합니다
  • 네이티브 PWA 설치 프롬프트를 트리거합니다
  • 다중 플랫폼에서 작동합니다
  • 필요한 설정 최소화
  • Flutter Web과의 통합
  • 브라우저 PWA API 활용

적합한 대상

  • 웹 중심 플러터 앱을 개발하는 개발자
  • 모바일 웹 사용자를 대상으로 하는 팀
  • 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
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

소스 저장소

이 패키지를 사용하는 프로젝트