Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从设备应用程序插件获取颤振中已安装应用程序的应用程序图标_Android_Flutter_Flutter Plugin - Fatal编程技术网

Android 从设备应用程序插件获取颤振中已安装应用程序的应用程序图标

Android 从设备应用程序插件获取颤振中已安装应用程序的应用程序图标,android,flutter,flutter-plugin,Android,Flutter,Flutter Plugin,我正在研究如何显示已安装应用程序的列表以及它们的名称和图标。在显示应用程序名称之前,代码运行良好。以下是正确的工作代码: import 'package:flutter/material.dart'; import 'package:device_apps/device_apps.dart'; import 'dart:async'; class FirstScreen extends StatefulWidget{ State<StatefulWidget> createSt

我正在研究如何显示已安装应用程序的列表以及它们的名称和图标。在显示应用程序名称之前,代码运行良好。以下是正确的工作代码:

import 'package:flutter/material.dart';
import 'package:device_apps/device_apps.dart';
import 'dart:async';

class FirstScreen extends StatefulWidget{
  State<StatefulWidget> createState(){
    return _FirstScreen();
  }
}

class _FirstScreen extends State<FirstScreen>{
  List<Application> apps;
  void initState(){
    super.initState();
  }

  Future<void> getApp() async{
    List<Application> _apps = await DeviceApps.getInstalledApplications(onlyAppsWithLaunchIntent: true, includeAppIcons: true, includeSystemApps: true);
    setState(() {
      apps = _apps;
    });
  }

  Widget build(BuildContext context) {
    getApp();
    return Container(
        child: ListView.builder(
          itemCount: apps.length,
          itemBuilder: (context, index){
            return ListTile(
              title: Text(apps[index].appName),
            );
          },
        )
    );
  }
}
它给出了错误


我甚至尝试了ApplicationWithIcon类,该类扩展了其中定义的应用程序类和图标,但它返回了,这是因为图标小部件接收图标小部件,而您正在传递图像

ej:
图标(Icons.home)

所以只需传递图像

trailing: Image.memory(apps[index].icon)
更新

必须删除类型并初始化列表:

 List apps = [];
在您的方法中也删除类型

Future getApp()异步{
列表_apps=await DeviceApps.getInstalledApplications(仅适用于具有启动意图的应用程序:true,
includeAppIcons:true,includeSystemApps:true);
设置状态(){
应用程序=_应用程序;
});
}
而不是写

List<Application> apps
还有,不是写,

List<Application> _apps = await DeviceApps.getInstalledApplications(onlyAppsWithLaunchIntent: true, includeAppIcons: true, includeSystemApps: true);
最后,不是

Icon(Image.memory(apps[index].icon))

Image.memory(apps[index] is ApplicationWithIcon ? app.icon : null)

同样的错误,&当我尝试使用ApplicationWithIcon时,它返回如上所述。这里是一个使用相同包的示例
 List _apps = await DeviceApps.getInstalledApplications(onlyAppsWithLaunchIntent: true, includeAppIcons: true, includeSystemApps: true);
Icon(Image.memory(apps[index].icon))
Image.memory(apps[index] is ApplicationWithIcon ? app.icon : null)