颤振呼叫功能使我无法导航到另一个屏幕



我想从P1屏幕导航到P2。P1包含一个移动到p2的按钮。P2包含一个获取文件的函数。当我在initState中传递这个函数时。导航变慢了。这是我的函数

Future<void> getFiles() async {
await Permission.manageExternalStorage.request();
if (await Permission.storage.request().isGranted) {
// Either the permission was already granted before or the user just granted it.
}
//asyn function to get list of files
List<StorageInfo> storageInfo = await PathProviderEx.getStorageInfo();
var root = storageInfo[0]
.rootDir; //storageInfo[1] for SD card, getting the root directory
var fm = FileManager(root: Directory(root)); //
files = await fm.filesTree(
excludedPaths: ["/storage/emulated/0/ssssssssssss"],
extensions: ["pdf"] //optional, to filter files, list only pdf files
);
setState(() {}); //update the UI
}

initstate

void initState() {
getFiles(); //call getFiles() function on initial state.
super.initState();

}

如果此函数耗时且影响主线程,请考虑使用Isolate

最新更新