diff options
author | Tomi Leppänen <tomi.leppanen@seafarix.com> | 2024-08-19 14:13:15 +0300 |
---|---|---|
committer | Tomi Leppanen <tomi.leppanen@seafarix.com> | 2024-11-11 12:59:02 +0000 |
commit | 9fcc67f7c92d2db9b89a1139533f8825a3834b2a (patch) | |
tree | 7111a7cd85fbf80a357c5c1653a523d5530e08fc /lib/presentation/screens | |
parent | 87c4e34f16555c70d590a56b522366599209b991 (diff) |
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 <tomi.leppanen@seafarix.com>
Diffstat (limited to 'lib/presentation/screens')
-rw-r--r-- | lib/presentation/screens/apps/widgets/app_button.dart | 28 |
1 files changed, 26 insertions, 2 deletions
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<AppButton> { 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( |