我正在弄清楚如何显示已安装应用程序的列表及其名称和图标。代码在显示应用名称之前运行良好。这是正确的工作代码:
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),
);
},
)
);
}
}
但是当我通过以下方式在 ListTile 中显示应用程序图标时:
trailing: Icon(Image.memory(apps[index].icon))
它给出了未定义图标的错误。
我什至尝试了ApplicationWithIcon类,它扩展了其中定义的 Application 类和图标,但它返回了Null 错误