import 'dart:io'; import 'package:path/path.dart' as p; import '../entities/album.dart'; class AlbumRepository { final String basePath; AlbumRepository({required this.basePath}); Future> getAllAlbums() async { final dir = Directory(basePath); if (!await dir.exists()) { return []; } var albums = await dir .list() .where((d) => d is Directory) .map((d) => d as Directory) .map((dir) { final name = p.basename(dir.path); return Album( id: dir.path.hashCode, name: name, createdAt: dir.statSync().changed, updatedAt: dir.statSync().changed, ); }) .toList(); return albums; } Future getAlbumById(int id) async { final albums = await getAllAlbums(); return albums.where((a) => a.id == id).firstOrNull; } }