You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hyzp_ybqx/lib/components/save_data_to_file.dart

35 lines
721 B
Dart

import 'dart:io';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
class StorageDataToFile {
static Future<String> get _localPath async {
final _path = await getTemporaryDirectory();
return _path.path;
}
static Future<File> get _localFile async {
final path = await _localPath;
return File('$path/counter.txt');
}
static Future<int> readCounter() async {
try {
final file = await _localFile;
var contents = await file.readAsString();
return int.parse(contents);
} catch (e) {
return 0;
}
}
static Future<File> writeCounter(counter) async {
final file = await _localFile;
return file.writeAsString('$counter');
}
}