0

The code should be working on flutter2, with android and ios(if possible)

Wali Khan
  • 586
  • 1
  • 5
  • 13

1 Answers1

1

Searching for files

import 'package:glob/glob.dart';

Stream<File> search(Directory dir) {
    return Glob("**.mp3")
      .list(root: dir.path)
      .where((entity) => entity is File)
      .cast<File>();
}
  • Do you want to avoid adding a new dependency in your project? Manipulate the Directory itself:
Stream<File> search(Directory dir) {
  return dir
    .list(recursive: true)
    .where((entity) => entity is File && entity.path.endsWith(".mp3"))
    .cast<File>();
}

Defining the search scope

You'll also need a Directory where you'll search for MP3 files.

  • Is it the root directory (i.e. search ALL the files in the device)? Use this answer.

  • Is it another directory? Pick one from this package.

Usage

final Directory dir = /* the directory you obtained in the last section */;
await search(dir).forEach((file) => print(file));
enzo
  • 9,861
  • 3
  • 15
  • 38