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