title: Flutter: Shared Storage (Storage Access Framework API) Permission for files inside hidden sub-directory not working
body: <p>How to achieve to listing all files (e.g. Media) inside hidden subdirectory i.e. folder name start with <strong>'.'</strong> e.g. &quot;<strong>(.media)</strong>&quot; after using SAF in Flutter/Dart?</p>
  <p>I have used ACTION_OPEN_DOCUMENT_TREE to let the user choose a folder <strong>[So to avoid using MANAGE_EXTERNAL_STORAGE]</strong> but couldn't view i.e. Read the files inside the hidden subdirectory of the folder.</p>
  <p><strong>Permission Granted folder is <em>media</em>:</strong></p>
  <p>storage/emulated/0/internal storage/Android/<strong>media</strong>/matrix/.new/</p>
  <p><strong>Issue:</strong></p>
  <p>Not able to list all files inside subfolder <strong>.new</strong></p>
  <p>At the same time...</p>
  <p>Able to access files (not folder) inside <strong>matrix</strong> subfolder</p>
  <p>Also if I rename the subfolder <strong>&quot;.new&quot;</strong> to <strong>new</strong> I am able to list all the files inside that folder</p>
  <p>I am using flutter/dart. For Shared Storage Permission, I have used <strong>Kotlin</strong> custom native code.</p>
  <p><strong>Kotlin Code:</strong></p>
  <pre><code>override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
  
          GeneratedPluginRegistrant.registerWith(flutterEngine)
  
          MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
  
                  .setMethodCallHandler{ call: MethodCall, result: MethodChannel.Result -&gt; run {
                                  if (call.method.contentEquals(&quot;getSAFPermission&quot;)) {
                                      if (VERSION.SDK_INT &gt; 29) {
                                          openDirectory(_initialPickerDirPath) //@String path
                                      } else {
                                          result.success(true)
                                      }
                                  }
                              }
                          }
  }
  
  private fun openDirectory(pickerInitialUri: String) { 
             val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {
              putExtra(DocumentsContract.EXTRA_INITIAL_URI,DocumentsContract.buildDocumentUri(
                  &quot;com.android.externalstorage.documents&quot;, pickerInitialUri)
                  }
  
              startActivityForResult(intent, SAF_PERMISSION_CODE)
  }
  
  override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
            if (requestCode == SAF_PERMISSION_CODE &amp;&amp; resultCode == Activity.RESULT_OK) {
  
               val contentResolver = applicationContext.contentResolver
  
               val takeFlags: Int = (Intent.FLAG_GRANT_READ_URI_PERMISSION or 
                                     Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
  
               contentResolver.takePersistableUriPermission(treeUri, takeFlags)
            }
  }
  </code></pre>
  <p>Flutter side | <strong>Dart Code</strong>:</p>
  <pre><code>_loadimage() async {
      // path: '/storage/emulated/0/Android/media/neo/matrix/.new'
      if (Directory(_neoDir.path).existsSync()) { // _neoDir: Directory
        imageList += _neodDir
            .listSync()
            .map((item) =&gt; item.path)
            .where((item) =&gt; item.endsWith(&quot;.jpg&quot;))
            .toList(growable: false); // imageList appear empty list
      }
  }
  </code></pre>
  <p><strong>Tried method:</strong></p>
  <p><strong>1.</strong> <em>In the native Kotlin side, fetched child document files using CachingDocumentFile and iterating over all DocumentFile and storing Uri list in string and sending it back to Flutter side. Rendering image File.fromUri() at dart side (Flutter)</em></p>
  <p>Refer - &gt; <a href="https://github.com/android/storage-samples/tree/main/ActionOpenDocumentTree" rel="nofollow noreferrer">https://github.com/android/storage-samples/tree/main/ActionOpenDocumentTree</a></p>
  <p><strong>2.</strong> <em>Used the solution of these folks.</em> Refer &gt; <a href="https://github.com/lakscastro/shared-storage/issues/10#issuecomment-1025801272" rel="nofollow noreferrer">https://github.com/lakscastro/shared-storage/issues/10#issuecomment-1025801272</a></p>
  <p>I feel I am not getting the read permission for child document files.</p>
  <p>Note:- As of <strong>31-Jan-2022</strong> No flutter package helps to achieve this functionality. <em>Tried given packages</em> <strong>:</strong></p>
  <p><strong>shared_storage</strong>, &gt; <a href="https://pub.dev/packages/shared_storage" rel="nofollow noreferrer">https://pub.dev/packages/shared_storage</a></p>
  <p><strong>file_picker</strong>, &gt; <a href="https://pub.dev/packages/file_picker" rel="nofollow noreferrer">https://pub.dev/packages/file_picker</a></p>
  <p><strong>filesystem_picker</strong>, &gt; <a href="https://pub.dev/packages/filesystem_picker" rel="nofollow noreferrer">https://pub.dev/packages/filesystem_picker</a></p>
  <p><strong>FileManager</strong> (<em>discontinued class</em>)</p>
  <p>Any help would be greatly appreciated.</p>