openMusicCollection function

Future<MusicCollection> openMusicCollection({
  1. SharedPreferencesAsync? prefs,
})

A coleção desta plataforma: no Android e no iOS, a pasta do app; no desktop, a pasta que o aluno escolheu (guardada em prefs).

Implementation

Future<MusicCollection> openMusicCollection({
  SharedPreferencesAsync? prefs,
}) async {
  if (Platform.isAndroid || Platform.isIOS) {
    final base = await getApplicationSupportDirectory();
    return FolderMusicCollection.app(Directory('${base.path}/musicas'));
  }
  final store = prefs ?? SharedPreferencesAsync();
  final saved = await store.getString(kMusicFolderKey);
  return FolderMusicCollection.picked(
    prefs: store,
    folder: saved == null || saved.isEmpty ? null : Directory(saved),
  );
}