From a4bbd6e843b16512d3110cf348722d0b46864791 Mon Sep 17 00:00:00 2001 From: dreautall <109872040+dreautall@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:43:03 +0000 Subject: [PATCH] remove deprecated device_apps package replace with AppCheck --- lib/pages/settings/notifications.dart | 25 +++++++++++++------------ pubspec.lock | 17 +++++++++-------- pubspec.yaml | 5 ++++- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/pages/settings/notifications.dart b/lib/pages/settings/notifications.dart index a893c9e7..6b6fb960 100644 --- a/lib/pages/settings/notifications.dart +++ b/lib/pages/settings/notifications.dart @@ -4,7 +4,7 @@ import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; import 'package:chopper/chopper.dart' show Response; -import 'package:device_apps/device_apps.dart'; +import 'package:appcheck/appcheck.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:notifications_listener_service/notifications_listener_service.dart'; @@ -173,18 +173,18 @@ class _SettingsNotificationsState extends State { onTap: () async { final SettingsProvider settings = context.read(); - Application? app = await showDialog( + AppInfo? app = await showDialog( context: context, builder: (BuildContext context) => const AppDialog(), ); - if (app == null || app.packageName.isEmpty) { + if (app == null || app.appName == null) { return; } await settings.notificationAddUsedApp(app.packageName); await settings.notificationSetAppSettings( app.packageName, - NotificationAppSettings(app.appName), + NotificationAppSettings(app.appName!), ); setState(() {}); }, @@ -453,18 +453,19 @@ class AppDialogEntry extends StatelessWidget { Widget build(BuildContext context) { final Logger log = Logger("Notifications.AppDialog.Entry"); - return FutureBuilder( - future: DeviceApps.getApp(app, true), - builder: (BuildContext context, AsyncSnapshot snapshot) { + return FutureBuilder( + future: AppCheck().checkAvailability(app), + builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.data == null) { + if (snapshot.data == null || snapshot.data!.appName == null) { return const SizedBox.shrink(); } late Widget leading; try { - final ApplicationWithIcon appIcon = - snapshot.data! as ApplicationWithIcon; - leading = Image.memory(appIcon.icon); + if (snapshot.data!.icon == null) { + throw Exception(); // will be caught below + } + leading = Image.memory(snapshot.data!.icon!); } catch (e) { leading = const Icon(Icons.api); } @@ -472,7 +473,7 @@ class AppDialogEntry extends StatelessWidget { leading: CircleAvatar( child: leading, ), - title: Text(snapshot.data!.appName), + title: Text(snapshot.data!.appName!), subtitle: Text(app), onTap: () { Navigator.pop(context, snapshot.data); diff --git a/pubspec.lock b/pubspec.lock index ccdea498..b65fdff4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -38,6 +38,15 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.3" + appcheck: + dependency: "direct main" + description: + path: "." + ref: ce371398f86412a8d9a2e0b75a9b51597ea1d79f + resolved-ref: ce371398f86412a8d9a2e0b75a9b51597ea1d79f + url: "https://github.com/bugrevealingbme/AppCheck.git" + source: git + version: "1.5.2" archive: dependency: transitive description: @@ -270,14 +279,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.10" - device_apps: - dependency: "direct main" - description: - name: device_apps - sha256: e84dc74d55749993fd671148cc0bd53096e1be0c268fc364285511b1d8a4c19b - url: "https://pub.dev" - source: hosted - version: "2.2.0" dynamic_color: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index a15da3d5..fae8d8d9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -34,7 +34,10 @@ dependencies: git: url: https://github.com/dreautall/notification_listener_service.git ref: 5f0d49d1b133943a6e6449059712514bf6506fd1 - device_apps: ^2.2.0 + appcheck: + git: + url: https://github.com/bugrevealingbme/AppCheck.git + ref: ce371398f86412a8d9a2e0b75a9b51597ea1d79f package_info_plus: ^8.0.2 logging: ^1.1.1 flutter_email_sender: ^6.0.2