'How i can display specific (pdf or mp3) files in a widget available in the root Directory

In this method I can see in which directory i in

Widget _buildDirectories(
  BuildContext context, AsyncSnapshot<List<Directory>?> snapshot) {
Text text = const Text('');
if (snapshot.connectionState == ConnectionState.done) {
  if (snapshot.hasError) {
    text = Text("Error: ${snapshot.error}");
  } else if (snapshot.hasData) {
    final String combined = snapshot.data!
        .map((Directory d) => Directory('/storage/emulated/0'))
        .join(", ");

    text = Text("Path: $combined");
  } else {
    text = const Text('Path Unavailable');
  }
}
return Center(
  child: text,
);

}

and I also enable the storage permissions

 void requestingPermission() async {
var status = await Permission.storage.status;
if (!status.isGranted) {
  await Permission.storage.request();
}

}

but i want to display the files in a widget such as in GridView.builder or ListView.build. and i wanna root directory files not the application document directory or anything..

If anyone could help me out i would be Thankful....



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source