reading and writing to a file flutter code example
Example 1: write and read to file in flutter
Future<File> get _localFile async {
final path = await _localPath;
return File('$path/counter.txt');
}
Example 2: write and read to file in flutter
Future<int> readCounter() async {
try {
final file = await _localFile;
String contents = await file.readAsString();
return int.parse(contents);
} catch (e) {
return 0;
}
}
Example 3: write and read to file in flutter
Future<String> get _localPath async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}