Skip to content

Directory.listSync does not return files #44848

@wim07101993

Description

@wim07101993

Thank you for taking the time to file an issue!

This tracker is for issues related to:

  • Dart core libraries ("dart:async", "dart:io", etc.)

SDK:
Dart SDK version: 2.10.3 (stable) (Tue Oct 27 14:44:30 2020 +0100) on "windows_x64"

Running on Google Pixel 4a Android 11 (Flutter)

Issue

While building an application which needs to be able to browse through local files. I think I stumped on a bug. The Direcotry.listSync (and also the Directory.list) methods do not return any files.

I have checked, there are files in the Download folder and I have tried in other directories as well.

Directories are listed, but files are not.

Steps to Reproduce

import 'dart:io';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final files = Directory('/storage/emulated/0/Download').listSync();
    print(files);
    return MaterialApp(
      home: Scaffold(
        body: ListView.builder(
          itemCount: files.length,
          itemBuilder: (context, i) => Text(files[i].path),
        ),
      ),
    );
  }
}

Related issue on flutter github:

flutter/flutter#75268

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-ioos-androidtype-questionA question about expected behavior or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions