file_util.dart 995 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'package:photo_manager/photo_manager.dart';
  2. import 'package:photos/core/cache/thumbnail_cache.dart';
  3. import 'package:photos/core/constants.dart';
  4. import 'package:photos/db/files_db.dart';
  5. import 'package:photos/models/file.dart';
  6. Future<void> deleteFiles(List<File> files,
  7. {bool deleteEveryWhere = false}) async {
  8. await PhotoManager.editor
  9. .deleteWithIds(files.map((file) => file.localID).toList());
  10. for (File file in files) {
  11. deleteEveryWhere
  12. ? await FilesDB.instance.markForDeletion(file)
  13. : await FilesDB.instance.delete(file);
  14. }
  15. }
  16. void preloadFile(File file) {
  17. // TODO
  18. }
  19. void preloadLocalFileThumbnail(File file) {
  20. if (file.localID == null ||
  21. ThumbnailLruCache.get(file, THUMBNAIL_SMALL_SIZE) != null) {
  22. return;
  23. }
  24. file.getAsset().then((asset) {
  25. asset
  26. .thumbDataWithSize(THUMBNAIL_SMALL_SIZE, THUMBNAIL_SMALL_SIZE)
  27. .then((data) {
  28. ThumbnailLruCache.put(file, THUMBNAIL_SMALL_SIZE, data);
  29. });
  30. });
  31. }