Skip to content

Instantly share code, notes, and snippets.

@ThinkDigitalSoftware
Created June 4, 2018 01:19
Show Gist options
  • Save ThinkDigitalSoftware/7976bdcf32716cf49d061037756a23d4 to your computer and use it in GitHub Desktop.
Save ThinkDigitalSoftware/7976bdcf32716cf49d061037756a23d4 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'dart:io';
main(List<String> arguments) async{
for (var i = 0; i < 10; i++) {
write(i.toString());
}
var fileContents = await readFile();
print(fileContents);
}
Future<String> get _localPath async {
final directory = new Directory("./");
return directory.path;
}
Future<File> get _localFile async {
final path = await _localPath;
return new File("$path/data");
}
Future<File> write(String contents) async {
final file = await _localFile;
return file.writeAsString("$contents\n", mode: FileMode.append);
}
Future<String> readFile() async {
final file = await _localFile;
try {
String result = await file.readAsString();
return result;
} catch (e) {
return "no results";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment