pwa_install 0.0.5 copy "pwa_install: ^0.0.5" to clipboard
pwa_install: ^0.0.5 copied to clipboard

A Flutter package that allows you to prompt mobile web users to install your Flutter app as a PWA

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:pwa_install/pwa_install.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

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

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

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomeView(),
      title: 'PWA Install',
    );
  }
}

class HomeView extends StatefulWidget {
  const HomeView({Key? key}) : super(key: key);

  @override
  State<HomeView> createState() => _HomeViewState();
}

class _HomeViewState extends State<HomeView> {

  String? error;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text('Version: 6'),
              Text('Launch Mode: ${PWAInstall().launchMode?.shortLabel}'),
              Text('Has Install Prompt: ${PWAInstall().hasPrompt}'),
              if(PWAInstall().installPromptEnabled) ElevatedButton(
                  onPressed: () {
                    try {
                      PWAInstall().promptInstall_();
                    } catch (e) {
                      setState(() {
                        error = e.toString();
                      });
                    }
                  },
                  child: const Text('Install')),
              if (error != null) Text(error!)
            ],
          ),
        ));
  }
}
81
likes
140
points
2.48k
downloads

Publisher

verified publishercodeontherocks.dev

Weekly Downloads

A Flutter package that allows you to prompt mobile web users to install your Flutter app as a PWA

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, js

More

Packages that depend on pwa_install