From c285f8e733d448555209f95fd76eedbeef5d9e24 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 2 Jun 2020 22:17:22 +0530 Subject: Adds application list component in apps view --- .flutter-plugins-dependencies | 1 + lib/components/AppList.dart | 33 ++++++++++++++++++++++++++++ lib/components/FixedContainer.dart | 34 +++++++++++++++++++++++++++++ lib/components/SearchableAppList.dart | 41 +++++++++++++++++++++++++++++++++++ lib/pages/Apps.dart | 26 +++++++++++++++++++++- lib/pages/Home.dart | 32 +++++++++------------------ pubspec.lock | 8 +++++++ pubspec.yaml | 4 +++- 8 files changed, 155 insertions(+), 24 deletions(-) create mode 100644 .flutter-plugins-dependencies create mode 100644 lib/components/FixedContainer.dart diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies new file mode 100644 index 0000000..2412e34 --- /dev/null +++ b/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"device_apps","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"device_apps","dependencies":[]}],"date_created":"2020-06-02 22:12:46.920929","version":"1.19.0-2.0.pre.214"} \ No newline at end of file diff --git a/lib/components/AppList.dart b/lib/components/AppList.dart index e69de29..5b54b04 100644 --- a/lib/components/AppList.dart +++ b/lib/components/AppList.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:device_apps/device_apps.dart'; + +class AppList extends StatelessWidget { + List appList; + void Function(Application) openApp; + void Function(Application) openOptionsMenu; + + AppList({ this.appList, this.openApp, this.openOptionsMenu }): super(); + + @override + Widget build(BuildContext ctx) { + return ListView.builder( + itemCount: appList.length, + itemBuilder: (ctx, index) { + Application app = appList[index]; + return Column( + children: [ + ListTile( + contentPadding: const EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0), + dense: true, + title: Text('${app.appName}', style: const TextStyle(fontSize: 16)), + onTap: () => openApp(app), + onLongPress: () => openOptionsMenu(app), + ), + Divider(height: 1.0), + ], + ); + }, + ); + } +} + diff --git a/lib/components/FixedContainer.dart b/lib/components/FixedContainer.dart new file mode 100644 index 0000000..99db1c8 --- /dev/null +++ b/lib/components/FixedContainer.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; +import 'package:device_apps/device_apps.dart'; + +import '../components/AppList.dart'; + +class FixedContainer extends StatelessWidget { + EdgeInsets padding; + Widget child; + + FixedContainer({ this.padding, this.child }): super(); + + @override + Widget build(BuildContext ctx) { + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints viewportConstraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: viewportConstraints.maxHeight, + ), + child: IntrinsicHeight( + child: Container( + padding: padding, + height: viewportConstraints.maxHeight, + child: child, + ) + ), + ), + ); + } + ); + } +} + diff --git a/lib/components/SearchableAppList.dart b/lib/components/SearchableAppList.dart index e69de29..8f9da2f 100644 --- a/lib/components/SearchableAppList.dart +++ b/lib/components/SearchableAppList.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:device_apps/device_apps.dart'; + +import 'AppList.dart'; + +class SearchableAppList extends StatelessWidget { + Future> appListF; + void Function(Application) openApp; + void Function(Application) openOptionsMenu; + + SearchableAppList({ this.appListF, this.openApp, this.openOptionsMenu }): super(); + + int _appSorter(Application a, Application b) { + return a.appName.compareTo(b.appName); + } + + @override + Widget build(BuildContext ctx) { + return Column( + children: [ + Text('My text input'), + Expanded(child: FutureBuilder( + future: appListF, + builder: (ctx, AsyncSnapshot> snap) { + if (!snap.hasData) { + return Text('Loading...'); + } + + snap.data.sort(_appSorter); + return AppList( + appList: snap.data, + openApp: openApp, + openOptionsMenu: openOptionsMenu, + ); + } + )), + ], + ); + } +} + diff --git a/lib/pages/Apps.dart b/lib/pages/Apps.dart index 3322c0b..7252aae 100644 --- a/lib/pages/Apps.dart +++ b/lib/pages/Apps.dart @@ -1,9 +1,33 @@ import 'package:flutter/material.dart'; +import 'package:device_apps/device_apps.dart'; + +import '../components/FixedContainer.dart'; +import '../components/SearchableAppList.dart'; class AppsView extends StatelessWidget { + Future> appListF = DeviceApps.getInstalledApplications( + includeSystemApps: false, + onlyAppsWithLaunchIntent: true, + ); + + void openApp(Application app) { + DeviceApps.openApp(app.packageName); + } + + void openOptionsMenu(Application app) { + debugPrint('Wow'); + } + @override Widget build(BuildContext ctx) { - return Text('Apps'); + return FixedContainer( + padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0), + child: SearchableAppList( + appListF: appListF, + openApp: openApp, + openOptionsMenu: openOptionsMenu, + ), + ); } } diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart index 4d28e29..1f4b473 100644 --- a/lib/pages/Home.dart +++ b/lib/pages/Home.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; +import '../components/FixedContainer.dart'; + class StatusInfoCard extends StatelessWidget { Stream time$; DateTime defaultTime; @@ -62,28 +64,14 @@ class HomeView extends StatelessWidget { @override Widget build(BuildContext ctx) { - return LayoutBuilder( - builder: (BuildContext context, BoxConstraints viewportConstraints) { - return SingleChildScrollView( - child: ConstrainedBox( - constraints: BoxConstraints( - minHeight: viewportConstraints.maxHeight, - ), - child: IntrinsicHeight( - child: Container( - padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0), - height: viewportConstraints.maxHeight, - child: Column( - children: [ - StatusInfoCard(time$, defaultTime: defaultTime), - Expanded(child: Text('Content')), - ], - ), - ) - ), - ), - ); - } + return FixedContainer( + padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0), + child: Column( + children: [ + StatusInfoCard(time$, defaultTime: defaultTime), + Expanded(child: Text('Content')), + ], + ) ); } } diff --git a/pubspec.lock b/pubspec.lock index 71c7b13..575cf93 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.3" + device_apps: + dependency: "direct main" + description: + name: device_apps + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.9" fake_async: dependency: transitive description: @@ -151,3 +158,4 @@ packages: version: "2.0.8" sdks: dart: ">=2.7.0 <3.0.0" + flutter: ">=1.10.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index af46be9..8c8f88f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,7 +23,9 @@ environment: dependencies: flutter: sdk: flutter - intl: 0.16.1 + intl: ^0.16.1 + device_apps: ^1.0.9 + # The following adds the Cupertino Icons font to your application. -- cgit v1.3.1