I let the user to save a backup file to his/her google drive, and save it to app’s folder. I also get a list of that backup files to the app until here every thing works fine, but if the user upload any file to that folder from outside the app e.g an image, so if the user hit the button recover, the app run an error, i just want to retrive the .db files only?
Future<List<drive.File>> _filesInFolder(drive.DriveApi driveApi) async {
var res = await driveApi.files.list(
spaces: 'drive',
q: "'$folderId' in parents and trashed=false",
);
return res.files??[];
}
>Solution :
You need to change the code as:
Future<Iterable<drive.File>> _filesInFolder(drive.DriveApi driveApi) async {
const dbExtension = '.db';
var res = await driveApi.files.list(
spaces: 'drive',
q: "'$folderId' in parents and trashed=false",
);
final file = res.files!.takeWhile(
(element) => element.name!.endsWith(dbExtension),
);
if (file.isEmpty) {
return [];
} else {
return file;
}
}
I don’t know how did you call it since you did not give us an enough code but I will imaging that you are adding it to a list so you should add also :
List<drive.File> _files = [];
And then fetch that files via calling the above function:
Future<void> _fetchFiles() async {
try {
var files = await _filesInFolder(driveFile);
_files = files.toList();
} catch (error) {
print("Error fetching files: $error");
}
}
Then you can call _fetchFiles
via FutureBuilder
widget.