Check if a particular app installed or not flutter

3.8k views Asked by At

I want to implement conditions in my existing app that a particular app is installed or not.

Conditions:

the first app is that which is I'm going to build

Second app that is required for run first app

  1. If the app is installed (Second app) then run HomePage() in the first app
  2. If the app is not installed then show a pop-up or alert for install the app.

Root Code of the first app

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
    future: Future.delayed(Duration(seconds: 2)),
        builder: (context, AsyncSnapshot snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return MaterialApp(
              home: Splash(),
              debugShowCheckedModeBanner: false,
            );
          } else {
            return StreamBuilder(
              stream: Connectivity().onConnectivityChanged,
              builder: (context, AsyncSnapshot<ConnectivityResult> snapshot) {
                return snapshot.data == ConnectivityResult.mobile ||
                        snapshot.data == ConnectivityResult.wifi
                    ? MaterialApp(
                        title: 'mFollower',
                        theme: ThemeData(
                          primarySwatch: Colors.blue,
                        ),
                        home: Homepage(),
                        debugShowCheckedModeBanner: false,
                      )
                    : NoInternet();
              },
            );
          }

        });
  }
}
1

There are 1 answers

7
Swaminathan V On

This can be achieved using the package device_apps package. This will return the list of apps installed in the Android device.

// All the apps installed in the device
List<Application> apps = await DeviceApps.getInstalledApplications();

So for your requirement you can do something like below

Future<bool> isAppInstalled() {
    return DeviceApps.getInstalledApplications().then((value) =>
        value.any((element) => element.packageName == 'com.example.app')); // Your app package id to check.
}

And inside build method use Future builder to get the result.

FutureBuilder<bool>(
        future: apps(),
        builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
          if (snapshot.hasData && snapshot.data) {
            // App is installed
            return Container(
              color: Colors.green,
            );
          } else {
            // App is not installed
            return Container(color: Colors.redAccent);
          }
        })

Unfortunately this plugin is supported only for ANDROID