listFiles method
Lists files in a directory.
Implementation
@override
Future<List<CloudFile>> listFiles(
{required String path, bool recursive = false}) async {
_checkAuth();
final List<CloudFile> allFiles = [];
String? cursor;
bool hasMore = true;
String initialPath = path == '/' ? '' : _normalizePath(path);
while (hasMore) {
Response response;
if (cursor == null) {
response = await _dio.post(
'https://api.dropboxapi.com/2/files/list_folder',
data: jsonEncode(
{'path': initialPath, 'recursive': recursive, 'limit': 1000}),
options: Options(contentType: 'application/json'),
);
} else {
response = await _dio.post(
'https://api.dropboxapi.com/2/files/list_folder/continue',
data: jsonEncode({'cursor': cursor}),
options: Options(contentType: 'application/json'),
);
}
final entries = response.data['entries'] as List;
allFiles.addAll(
entries.map((e) => _mapToCloudFile(e as Map<String, dynamic>)));
hasMore = response.data['has_more'] as bool;
cursor = response.data['cursor'] as String?;
}
return allFiles;
}