appcheck 1.5.2 copy "appcheck: ^1.5.2" to clipboard
appcheck: ^1.5.2 copied to clipboard

Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

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

void main() {
  runApp(const AppCheckExample());
}

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

  @override
  State<AppCheckExample> createState() => _AppCheckExampleState();
}

class _AppCheckExampleState extends State<AppCheckExample> {
  final appCheck = AppCheck();

  List<AppInfo>? installedApps;
  List<AppInfo> iOSApps = [
    AppInfo(appName: "Calendar", packageName: "calshow://"),
    AppInfo(appName: "Facebook", packageName: "fb://"),
    AppInfo(appName: "Whatsapp", packageName: "whatsapp://"),
  ];

  @override
  void initState() {
    getApps();
    super.initState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> getApps() async {
    if (Platform.isAndroid) {
      const package = "com.google.android.apps.maps";
      installedApps = await appCheck.getInstalledApps();
      debugPrint(installedApps.toString());

      await appCheck.checkAvailability(package).then(
            (app) => debugPrint(app.toString()),
          );

      await appCheck.isAppEnabled(package).then(
            (enabled) => enabled
                ? debugPrint('$package enabled')
                : debugPrint('$package disabled'),
          );

      installedApps?.sort(
        (a, b) => a.appName!.toLowerCase().compareTo(b.appName!.toLowerCase()),
      );
    } else if (Platform.isIOS) {
      // iOS doesn't allow to get installed apps.
      installedApps = iOSApps;

      await appCheck.checkAvailability("calshow://").then(
            (app) => debugPrint(app.toString()),
          );
    }

    setState(() {
      installedApps = installedApps;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(title: const Text('AppCheck Example App')),
        body: installedApps != null && installedApps!.isNotEmpty
            ? ListView.builder(
                itemCount: installedApps!.length,
                itemBuilder: (context, index) {
                  final app = installedApps![index];

                  return ListTile(
                    title: Text(app.appName ?? app.packageName),
                    subtitle: Text(
                      (app.isSystemApp ?? false) ? 'System App' : 'User App',
                    ),
                    trailing: IconButton(
                      icon: const Icon(Icons.open_in_new),
                      onPressed: () {
                        ScaffoldMessenger.of(context).hideCurrentSnackBar();
                        appCheck.launchApp(app.packageName).then((_) {
                          debugPrint(
                            "${app.appName ?? app.packageName} launched!",
                          );
                        }).catchError((err) {
                          ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                            content: Text(
                              "${app.appName ?? app.packageName} not found!",
                            ),
                          ));
                          debugPrint(err.toString());
                        });
                      },
                    ),
                  );
                },
              )
            : const Center(child: Text('No installed apps found!')),
      ),
    );
  }
}
92
likes
160
pub points
97%
popularity

Publisher

verified publisheryashgarg.dev

Flutter plugin that allows you to check if an app is installed/enabled, launch an app and get the list of installed apps.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on appcheck