apk_admin 2.2.4 copy "apk_admin: ^2.2.4" to clipboard
apk_admin: ^2.2.4 copied to clipboard

PlatformAndroid

A Flutter plugin for launching, installing from backup, uninstalling and sharing android apps and more!.

example/lib/main.dart

// Copyright 2020 Ammar Yasser. All rights reserved.
// Use of this source code is governed by a GPL v3 license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

import 'package:apk_admin/apk_admin.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  ApkScouter apkScouter = ApkScouter();
  ApkController apkController = ApkController();
  ApkBackup apkBackup = ApkBackup();
  ApkExporter apkExporter = ApkExporter();

  Widget buildOptionButton(String title, Function action) {
    return MaterialButton(
      padding: EdgeInsets.all(0),
      onPressed: () => action(),
      child: Text(
        title,
        style: TextStyle(color: Colors.blueGrey, fontSize: 18),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: RefreshIndicator(
          // refresh the apps list after any app removal
          onRefresh: () async {
            return await Future.sync(() {
              setState(() {});
            });
          },
          child: Scaffold(
            drawer: Drawer(
              child: Column(
                children: <Widget>[
                  Text(
                    "Backups",
                    style: TextStyle(fontSize: 25),
                  ),
                  Expanded(
                    child: FutureBuilder<Map?>(
                      future: apkScouter.getBackups(),
                      builder: (context, snapshot) {
                        if (snapshot.hasData) {
                          List backups = snapshot.data!.keys.toList();
                          return ListView.builder(
                            itemCount: backups.length,
                            itemBuilder: (context, i) {
                              return TextButton(
                                onPressed: () async {
                                  String apkPath = snapshot.data![backups[i]];
                                  await apkBackup.restoreAppFromBackup(apkPath);
                                },
                                child: Text(
                                  "${backups[i]}",
                                  textAlign: TextAlign.center,
                                ),
                              );
                            },
                          );
                        }
                        return Center(child: CircularProgressIndicator());
                      },
                    ),
                  ),
                ],
              ),
            ),
            appBar: AppBar(
              centerTitle: true,
              title: Text('APK admin'),
            ),
            body: FutureBuilder<List<App>>(
              future: apkScouter.getInstalledApps(includeAppIcon: true),
              builder: (context, snapshot) {
                if (snapshot.hasData) {
                  List<App> apps = snapshot.data!;
                  return ListView.builder(
                    itemCount: apps.length,
                    itemBuilder: (context, i) => Card(
                      elevation: 5,
                      child: Container(
                        color: Colors.white,
                        padding: EdgeInsets.all(5),
                        child: Column(
                          children: <Widget>[
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: <Widget>[
                                Image.memory(
                                  apps[i].decodedIcon!,
                                  height: 70,
                                  width: 70,
                                ),
                                Flexible(
                                  child: Column(
                                    children: <Widget>[
                                      Text(apps[i].appName!),
                                      Text(apps[i].packageName!),
                                    ],
                                  ),
                                ),
                                SizedBox(width: 5),
                                TextButton(
                                  style: ButtonStyle(
                                    backgroundColor:
                                        MaterialStateProperty.all(Colors.blue),
                                    shape: MaterialStateProperty.all(
                                        StadiumBorder()),
                                  ),
                                  child: Text(
                                    "UNINSTALL",
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 16,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                  onPressed: () async {
                                    await apkController
                                        .uninstallApp(apps[i].packageName!);
                                  },
                                ),
                              ],
                            ),
                            Column(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Text(
                                  "version name: ${apps[i].versionName}",
                                ),
                                Text(
                                  "install date: ${apps[i].installDate}",
                                ),
                                Text(
                                  "last update date: ${apps[i].lastUpdateDate}",
                                ),
                              ],
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: <Widget>[
                                buildOptionButton("LAUNCH", () async {
                                  await apkController
                                      .launchApp(apps[i].packageName!);
                                }),
                                buildOptionButton("BACKUP", () async {
                                  await apkBackup
                                      .makeBackup(apps[i].packageName!);
                                  setState(() {});
                                }),
                                buildOptionButton("SHARE", () async {
                                  await apkExporter.shareAppViaBluetooth(
                                      apps[i].packageName!);
                                }),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                  );
                }
                return Center(child: CircularProgressIndicator());
              },
            ),
          ),
        ),
      ),
    );
  }
}
34
likes
130
pub points
52%
popularity

Publisher

unverified uploader

A Flutter plugin for launching, installing from backup, uninstalling and sharing android apps and more!.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on apk_admin