42 lines
1.0 KiB
Dart
42 lines
1.0 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:gallery/data_provider/data_provider.dart';
|
|
|
|
class LocalDataProvider extends DataProvider {
|
|
final Future<Directory> initialPath;
|
|
|
|
LocalDataProvider(this.initialPath);
|
|
|
|
@override
|
|
Future<void> connect() async {}
|
|
|
|
@override
|
|
Future<Folder> listOfFiles({Uri? uri}) async {
|
|
final dir = uri != null ? Directory.fromUri(uri) : await initialPath;
|
|
|
|
final list = dir.listSync();
|
|
final List<Item> res = [];
|
|
|
|
for (var val in list) {
|
|
if (validSuffix.any((suff) => val.path.endsWith(suff))) {
|
|
res.add(Item(false, val.uri, val.uri.pathSegments.last));
|
|
} else if (await FileSystemEntity.isDirectory(val.path)) {
|
|
res.add(
|
|
Item(true, val.uri, val.uri.pathSegments.reversed.skip(1).first));
|
|
}
|
|
}
|
|
|
|
res.sort(
|
|
(a, b) => b.isFolder ? 1 : -1,
|
|
);
|
|
|
|
return Folder(res, dir.uri, dir.parent.uri);
|
|
}
|
|
|
|
@override
|
|
ImageProvider getImageProvider(Uri uri) {
|
|
return FileImage(File.fromUri(uri));
|
|
}
|
|
}
|