getID method
Implementation
Future<String?> getID(String filename, {String? mimeType, bool createIfMissing = false}) async {
if(!await ready()) return null;
try{
if(filename == "" || filename == "/") return wd;
var parentID = wd;
var split = filename.split("/");
List<File>? out;
for(int i = 0; i< split.length; i++){
var fold = split[i];
if(fold == "") continue;
var query = DriveQueryBuilder();
if(i != split.length -1){
query.mime = DriveQueryBuilder.folderMime;
}else{
query.mime = mimeType;
}
query.name = fold;
query.parent = parentID;
out = (await api!.files.list(
spaces: (scope == DriveApi.driveAppdataScope) ? "appDataFolder" : "drive",
q: query.getQuery()
)).files;
if (out == null || out.isEmpty) {
if (!createIfMissing) return null;
var id = await createFileWithParent(fold, parentID);
if (id == null) return null;
parentID = id;
continue;
}
if(out[0].id == null) {
if (!createIfMissing) return null;
var id = await createFileWithParent(fold, parentID);
if (id == null) return null;
parentID = id;
continue;
}
parentID = out[0].id!;
}
return out![0].id;
}catch(e, stack){
if(e is PlatformException && e.code == "network_error"){
return null;
}
if(kDebugMode){
print("getID:");
print("${e.toString()}\n${stack.toString()}");
}else if (onError != null){
onError!(e, stack);
}
return null;
}
}