flutter_plugin_device_apps icon indicating copy to clipboard operation
flutter_plugin_device_apps copied to clipboard

Cannot use Image.memory(app.icon); in the project

Open Sankalpjadhav opened this issue 4 years ago • 8 comments

Is it possible to get the applications icon by any other method?

Sankalpjadhav avatar Jul 03 '20 12:07 Sankalpjadhav

Why can't you use this method?

g123k avatar Jul 18 '20 06:07 g123k

Can you please tell me how to get app icon based on the app name?

Sankalpjadhav avatar Jul 22 '20 05:07 Sankalpjadhav

You just have to cast the Object from Application to ApplicationWithIcon

g123k avatar Aug 09 '20 17:08 g123k

Check this out https://github.com/g123k/flutter_plugin_device_apps/issues/20#issuecomment-661076132

jspw avatar Sep 21 '20 07:09 jspw

@g123k i want to save the app.icon loaclly and use it later but not able to use it as it's saying type 'List<dynamic>' is not a subtype of type 'Uint8List How can i solve this?

jspw avatar Sep 21 '20 08:09 jspw

Just Find a solution and don't know why it works ! But there is a problm! Sometimes it works and sometimes doesn't! take app.icon in a variable before using it in Image.memory()

ApplicationWithIcon iconx = app  as ApplicationWithIcon;
var icon = iconx.icon;

Image.memory(icon);

jspw avatar Sep 25 '20 02:09 jspw

My quick workaround as @jspw mentioned, so was something like that

icon: snapshot.data[index] is ApplicationWithIcon
                                ? CircleAvatar(
                                    backgroundImage: MemoryImage((snapshot
                                            .data[index] as ApplicationWithIcon)
                                        .icon),
                                    backgroundColor: Colors.white,
                                  )
                                : null,

result:" image

thiagoloureiro avatar Dec 13 '20 19:12 thiagoloureiro

I don't know if there is still a problem, because the issue is still open, but you can simply get all apps by creating a simple Future: Future<List<Application>> _getApps() async { return await DeviceApps.getInstalledApplications( includeSystemApps: true, onlyAppsWithLaunchIntent: true, includeAppIcons: true); }

(Don't forget to include the includeAppIcons: true property.)

Now you've got a List of "Application's".

Now you can simply cast an 'Application' to an 'ApplicationWithIcon' like this: ApplicationWithIcon applicationWithIcon = apps[index] as ApplicationWithIcon;

The only thing you have to do now is to use the "icon" value in the "Image.memory()" widget to display it on the screen. Image.memory(applicationWithIcon.icon)

musiolmarco avatar Jan 12 '21 05:01 musiolmarco