Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

dart - Accessing and Opening File in the Local Directory in Flutter

I have this bit of code that exports a list into a csv file. It saves it on the device, but I don't know how to actually access the file itself, here is the code:

  getCsv(List<Email> mailList) async {
    List<List<dynamic>> rows = List<List<dynamic>>();
    for (int i = 0; i < mailList.length; i++) {
      List<dynamic> row = List();
      row.add(mailList[i].id);
      row.add(mailList[i].email);
      rows.add(row);
      setState(() {
        mailList = finalExport;
      });
      
    }
    await SimplePermissions.requestPermission(Permission.WriteExternalStorage);
    bool checkPermission = await SimplePermissions.checkPermission(
        Permission.WriteExternalStorage);
    if (checkPermission) {
      String dir =
          (await getExternalStorageDirectory()).absolute.path + "/user";
      String file = "$dir";
      File f = new File(file + "_maillist.csv");
      String csv = const ListToCsvConverter().convert(rows);
      f.writeAsString(csv);
      
     
    }
  }

And firing that function, it saves it here on the emulator:

'/storage/emulated/0/Android/data/com.example.myapp/files/user_maillist.csv'

How would I actually be able to access that file on my device, maybe copy it to somewhere where I can open it or even maybe send that file through mail, just so I can actually open it. Thank you!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...