android_package_manager 0.5.0 copy "android_package_manager: ^0.5.0" to clipboard
android_package_manager: ^0.5.0 copied to clipboard

Provides access to Android's native PackageManager API to fetch various information, such as installed applications, packages, permissions, etc.

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';

import 'package:android_package_manager/android_package_manager.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MainPage(),
    );
  }
}

class MainPage extends StatefulWidget {

  const MainPage({Key? key}) : super(key: key);

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {

  @override
  void initState() {
    super.initState();
    AndroidPackageManager().getInstalledApplications().then(
      (value) => setState(
        () => _applicationInfoList = value,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {

    final appInfo = _applicationInfoList;
    return Scaffold(
      appBar: AppBar(
        title: const Text("Android Package Manager Demo",),
      ),
      body: ListView.builder(
        padding: const EdgeInsets.symmetric(
          horizontal: 24.0, vertical: 32.0,
        ),
        itemBuilder: (_, index,) {
          final info = appInfo![index];
          return Padding(
            padding: const EdgeInsets.symmetric(
              vertical: 12.0,
            ),
            child: Card(
              child: ListTile(
                leading: SizedBox.square(
                  dimension: 48.0,
                  child: FutureBuilder<Uint8List?>(
                    future: info.getAppIcon(),
                    builder: (context, snapshot,) {
                      if (snapshot.hasData) {
                        final iconBytes = snapshot.data!;
                        return Image.memory(
                          iconBytes,
                          fit: BoxFit.fill,
                        );
                      }
                      if (snapshot.hasError) {
                        return const Icon(Icons.error, color: Colors.red,);
                      }
                      return const SizedBox.shrink();
                    },
                  ),
                ),
                title: Text(info.name ?? "No Name",),
                subtitle: Text(info.packageName ?? "-",),
              ),
            ),
          );
        },
        itemCount: appInfo?.length ?? 0,
      ),
    );
  }

  List<ApplicationInfo>? _applicationInfoList;
}
11
likes
0
points
1.55k
downloads

Publisher

unverified uploader

Weekly Downloads

Provides access to Android's native PackageManager API to fetch various information, such as installed applications, packages, permissions, etc.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on android_package_manager