From 9fcc67f7c92d2db9b89a1139533f8825a3834b2a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomi=20Lepp=C3=A4nen?= Date: Mon, 19 Aug 2024 14:13:15 +0300 Subject: [PATCH] Add support for application icons in Apps MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add support for SVG and PNG application icons in Apps. Assets should continue to work the same way as before. Applications that provide their own icons can use either SVG or PNG icons. Bug-AGL: SPEC-5268 Change-Id: I99b4997510e3eb9380afb43f81bcd64efdc92c8f Signed-off-by: Tomi Leppänen --- lib/data/data_providers/app_launcher.dart | 2 +- .../screens/apps/widgets/app_button.dart | 28 ++++++++++++++++++++-- pubspec.lock | 8 +++++++ pubspec.yaml | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/data/data_providers/app_launcher.dart b/lib/data/data_providers/app_launcher.dart index 917dd21..693ce29 100644 --- a/lib/data/data_providers/app_launcher.dart +++ b/lib/data/data_providers/app_launcher.dart @@ -58,7 +58,7 @@ class AppLauncher { debugPrint("$info"); // Existing icons are currently not usable, so leave blank for now apps.add(AppLauncherInfo( - id: info.id, name: info.name, icon: "", internal: false)); + id: info.id, name: info.name, icon: info.iconPath, internal: false)); } apps.sort((a, b) => a.name.compareTo(b.name)); diff --git a/lib/presentation/screens/apps/widgets/app_button.dart b/lib/presentation/screens/apps/widgets/app_button.dart index 2e016ca..336e1e2 100644 --- a/lib/presentation/screens/apps/widgets/app_button.dart +++ b/lib/presentation/screens/apps/widgets/app_button.dart @@ -1,5 +1,6 @@ import 'package:flutter_ics_homescreen/core/utils/helpers.dart'; import 'package:flutter_ics_homescreen/export.dart'; +import 'package:mime/mime.dart'; class AppButton extends StatefulWidget { const AppButton( @@ -38,8 +39,31 @@ class _AppButtonState extends State { Padding( padding: const EdgeInsets.only( left: 10, right: 10, top: 6, bottom: 6), - child: SvgPicture.asset( - "assets/${widget.image}", + child: Builder( + builder: (BuildContext context) { + var filepath = widget.image; + final file = File(filepath); + if (file.existsSync()) { + final String? mimeType = lookupMimeType(filepath); + if (mimeType == 'image/png') { + return Image.file( + file, + width: 160, + height: 160, + fit: BoxFit.contain, + ); + } else if (mimeType == 'image/svg+xml') { + return SvgPicture.file( + file, + width: 160, + height: 160, + fit: BoxFit.contain, + ); + } + filepath = "app-generic.svg"; + } + return SvgPicture.asset("assets/${filepath}"); + }, ), ), Text( diff --git a/pubspec.lock b/pubspec.lock index f256dbb..51c7761 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -380,6 +380,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.15.0" + mime: + dependency: "direct main" + description: + name: mime + sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + url: "https://pub.dev" + source: hosted + version: "2.0.0" nested: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 1304544..b23d600 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,7 @@ dependencies: flutter_calendar_carousel: path: ./packages/flutter_calendar_carousel dart_mpd: ^0.4.1 + mime: ^2.0.0 dev_dependencies: flutter_test: -- 2.16.6