import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:gallery/data_provider/data_provider.dart'; class LocalDataProvider extends DataProvider { final String initialPath; LocalDataProvider(this.initialPath); @override Future connect() async {} @override Future listOfFiles({Uri? uri}) async { final dir = uri != null ? Directory.fromUri(uri) : Directory(initialPath); final list = dir.listSync(); final List 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)); } }