是否有垃圾屏幕(启动屏幕) 一直显示到应用所需的数据准备就绪?
manifest.xml中还有以下其他选项吗? “ io.flutter.app.android.SplashScreenUntilFirstFrame”
答案 0 :(得分:0)
多次重试后,我发现了可以优化的解决方案。 请告诉我您的意见
通常扑打始于
void main() => runApp(new MyApp());
我首先通过修改代码插入了数据采集
void main() async {
final OrderedAppList aList = new OrderedAppList(); //class to get all data
var funx = (int) async => aList.getit(); //to get all of the data
var value;
value = await funx(1); //should wait for the return value
runApp(new MyApp(
qallUserApps: aList.allUserApps,
qlistLen: value, // means aList.listLen,
qplatformVersion: aList.platformVersion,
qmodel: aList.model
));
}
在MyApp中:
class MyApp extends StatelessWidget {
final List qallUserApps;
final int qlistLen;
final String qplatformVersion;
final String qmodel;
// Constructor:
const MyApp({Key key, this.qallUserApps,
this.qlistLen,
this.qplatformVersion,
this.qmodel})
: super(key: key);
@override
Widget build(BuildContext context) {
// ...
}
OrderedAppList类的代码部分:
class OrderedAppList {
int listLen= -1;
String platformVersion = "Unknown Platform";
String model = "Unknown Platform";
List allUserApps = null;
Future<int> getit() async {
try {
allUserApps = await AppsAsStateless.allApps;
listLen = allUserApps.length;
} on Exception {
allUserApps = null;
listLen = 0;
}
// ...
return listLen ;
}
感谢阅读!
答案 1 :(得分:0)
它工作正常并且 可以优化main中的代码:
void main() async { // async that data acquisition done before any widgets shown
final OrderedAppList aList = new OrderedAppList();
int value;
value = await aList.getit();
runApp(new MyApp(
qallUserApps: aList.allUserApps,
qlistLen: value, // = aList.listLen,
qplatformVersion: aList.platformVersion,
qmodel: aList.model
));
}