getAllFiles method

  1. @override
Future<List<FileModel>> getAllFiles({
  1. DateTime? fromDate,
  2. int? limit,
  3. bool orderByDesc = true,
  4. bool sortBySize = false,
  5. bool sortByName = false,
  6. List<String> fileExtensions = const ['pdf', 'txt', 'zip'],
  7. String? keyword,
})
override

Fetches all files with specified extensions from the device.

Implementation

@override
Future<List<FileModel>> getAllFiles({
  DateTime? fromDate,
  int? limit,
  bool orderByDesc = true,
  bool sortBySize = false,
  bool sortByName = false,
  List<String> fileExtensions = const ['pdf', 'txt', 'zip'],
  String? keyword,
}) async {
  if (fileExtensions.isEmpty) {
    throw ArgumentError('fileExtensions cannot be empty');
  }

  final Map<String, dynamic> arguments = {
    'fromDate': fromDate?.millisecondsSinceEpoch,
    'limit': limit,
    'orderByDesc': orderByDesc,
    'sortBySize': sortBySize,
    'sortByName': sortByName,
    'fileExtensions': fileExtensions,
    'keyword': keyword,
  };

  final result = await methodChannel.invokeMethod<List<dynamic>>(
    'getAllFiles',
    arguments,
  );
  return result
          ?.map((e) => FileModel.fromMap(Map<String, dynamic>.from(e)))
          .toList() ??
      [];
}