title: How to save images from assets to the internal storage in flutter?
body: <p>I am trying to save the image from assets to internal storage. But, I could not load the image from assets to file. Here is what I have done:</p>
  <pre><code>onTap: () async {
    
    final String documentPath = (await getApplicationDocumentsDirectory()).path;
    String imgPath = (galleryItems[currentIndex].assetName).substring(7);
    File image = await getImageFileFromAssets(imgPath);
  
    print(image.path);
  }
  </code></pre>
  <p>I used <code>substring(7)</code> to eliminate <code>assets/</code> as, my assetName comes as <code>assets/images/foo.jpg</code>.</p>
  <pre><code>Future&lt;File&gt; getImageFileFromAssets(String path) async {
    final byteData = await rootBundle.load('assets/$path');
  
    final file =
        await File('${(await getApplicationDocumentsDirectory()).path}/$path')
            .create(recursive: true);
    await file.writeAsBytes(byteData.buffer
        .asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
  
    return file;
  }
  </code></pre>
  <p>After I get <code>image</code>, I don't know how to proceed forward to create a directory with my name in internal storage. And, copy file there.</p>
  <p>*Note:- I have editted the post, as some basic mistakes were pointed out.</p>
  <h2>Update</h2>
  <p>Here is what I came up with. And it saves image in the <code>/storage/emulated/0/Android/data/com.example.my_project/files/Pics/foo.jpg</code> path.</p>
  <pre><code>File image = await getImageFileFromAssets(imgPath);
  
  final extDir = await getExternalStorageDirectory();
  
  // Path of file
  final myImagePath = '${extDir.path}/Pics';
  
  // Create directory inside where file will be saved
  await new Directory(myImagePath).create();
  
  // File copied to ext directory.
  File newImage =
      await image.copy(&quot;$myImagePath/${basename(imgPath)}&quot;);
  
  print(newImage.path);
  </code></pre>
  <p>Here are some links that really helped me:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/54565279/flutter-how-to-save-image-file-to-new-folder-in-gallery">Flutter How to save Image file to new folder in gallery?</a></li>
  <li><a href="https://stackoverflow.com/questions/51338041/how-to-save-image-file-in-flutter-file-selected-using-image-picker-plugin">How to Save Image File in Flutter ? File selected using Image_picker plugin</a></li>
  <li><a href="https://stackoverflow.com/questions/55295593/how-to-convert-asset-image-to-file">How to convert asset image to File?</a></li>
  </ul>
  <p>Special thanks to @David for the help. Please see comments to understand full scene if you are here to solve your similar problem.</p>
  <p>So, I am accepting the answer from @David.</p>