device_apps 1.0.0
device_apps: ^1.0.0 copied to clipboard
Plugin to get the list of applications installed on the device (Android only)
example/lib/main.dart
import 'package:device_apps/device_apps.dart';
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: ListAppsPages()));
class ListAppsPages extends StatefulWidget {
@override
_ListAppsPagesState createState() => _ListAppsPagesState();
}
class _ListAppsPagesState extends State<ListAppsPages> {
bool _showSystemApps = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Installed applications"),
actions: <Widget>[
PopupMenuButton(
itemBuilder: (context) {
return <PopupMenuItem<String>>[
PopupMenuItem<String>(
value: 'system_apps', child: Text('Toggle system apps')),
];
},
onSelected: (key) {
if (key == "system_apps") {
setState(() {
_showSystemApps = !_showSystemApps;
});
}
},
)
],
),
body: _ListAppsPagesContent(includeSystemApps: _showSystemApps),
);
}
}
class _ListAppsPagesContent extends StatelessWidget {
final bool includeSystemApps;
_ListAppsPagesContent({this.includeSystemApps: false});
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: DeviceApps.getInstalledApplications(
includeSystemApps: includeSystemApps),
builder: (context, data) {
if (data.data == null) {
return Center(child: CircularProgressIndicator());
} else {
List<Application> apps = data.data;
return ListView.builder(
itemBuilder: (context, position) {
Application app = apps[position];
return Column(
children: <Widget>[
ListTile(
title: Text("${app.appName} (${app.packageName})"),
subtitle: Text("Version : ${app.versionName}")),
Divider(
height: 1.0,
)
],
);
},
itemCount: apps.length);
}
});
}
}