flutterdartfile-handling

Flutter: How to write data from List<String> into a File in Dart


I'm trying to copy all Strings from a List into a File but only a few Strings are being copied.

I'm using path_provider pkg from pub.dev to create a file on the User's device.

Explored questions related to File Handling but couldn't find what I was looking for.

Here is my CODE:

final Directory? externalStorageDirectoryPath =
    await getExternalStorageDirectory();
if (externalStorageDirectoryPath != null) {
  File file = File('${externalStorageDirectoryPath.path}/contacts.vcf');

  for (int i = 0; i < vCardsList.length; i++) {
    file.writeAsString(vCardsList[i], mode: FileMode.writeOnlyAppend);
  }

Any help would be appreciated!


Solution

  • Calling '.join()' on my List resolved the issue.