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

outdated

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
0
pub points
90%
popularity

Publisher

verified publishercodeontherocks.dev

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, js

More

Packages that depend on pwa_install