getFileID method

Future<List<String>> getFileID(
  1. String fileName
)

Get the file ID of a file from its fileName

If multiple files with the same name exist, their IDs will be returned in a list.

This only searches for items that are not trashed.

Implementation

Future<List<String>> getFileID(String fileName) async {
  final search = await driveAPI.files.list(
    q: "name='$fileName' and trashed=false",
    spaces: "drive" +
        (signIn.scopes.contains(DriveApi.driveAppdataScope)
            ? ", appDataFolder"
            : ""),
  );

  List<String> result = List.empty(growable: true);
  if (search.files == null || search.files!.length == 0) {
    throw "File not found";
  } else {
    search.files!.forEach((file) => result.add(file.id!));
  }
  return result;
}