[英]Cannot create a file in flutter
I have tried this code below but an empty folder i have found and still cannot create a file, but no errors found in the terminal.我在下面尝试了这段代码,但我找到了一个空文件夹,仍然无法创建文件,但在终端中没有发现错误。
here is the packages i have used:这是我用过的包:
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:io';
this is the codes to create the file, is there something wrong:这是创建文件的代码,有什么问题吗:
Future<String> getFilePath() async {
Directory? appExtDirectory = await getExternalStorageDirectory();
String appExtPath = appExtDirectory.toString();
print('$appExtPath');
return appExtPath;
}
Future<File> get _localFile async {
final path = await getFilePath();
return File('$path/counter.txt');
}
Future<File> writeCounter() async {
final file = await _localFile;
// Write the file
return file.writeAsString("This is my demo text that will be saved to : counter.txt");
}
void saveFile() {
writeCounter();
}
Regards..问候..
Try String appExtPath = appExtDirectory.path;
试试String appExtPath = appExtDirectory.path;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.