I want to save data from my TextField
in my device. I accomplish this by TextEditingController
. But now, I want to do that dynamically. I will have meany TextField's and I only learned how to do it statically. Can someone write demo application showing how I should do it, or explain somehow?
I was trying to find anything on the internet, sadly I didn't
(in the end, I want my application to use this data if I close application or restart phone)
This class is saving data statically, but I think the problem is with controller:
class Storage {
//gets path of the file
Future<String> get _localPath async {
final dir = await getApplicationDocumentsDirectory();
return dir.path;
}
//gets the location of the file
Future<File> get _localFile async {
final path = await _localPath;
return File("$path/db.txt");
}
//write to the file
Future<File> writeData(String message) async {
final file = await _localFile;
return file.writeAsString("$message");
}
//read from the file
Future<String> readData() async {
try {
final file = await _localFile;
String body = await file.readAsString();
return body;
} catch (e) {
return e.toString();
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…