Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Future<File> _getCacheFile() async {
final dir = (await getApplicationDocumentsDirectory()).path;
return new File('$dir/hotlist.xml');
Future<XmlDocument> _getHotListCache() async {
try {
final file = await _getCacheFile();
return parse(await file.readAsString());
on FileSystemException {
return _getDefaultHotGameInfo();
Future<bool> _hotListCacheFileExists() async =>
await (await _getCacheFile()).exists();
Future<Null> _saveHotListToCache(XmlDocument doc) async {
try {
final file = await _getCacheFile();
final sink = await file.openWrite();
await sink.write(doc.toXmlString(pretty: true));
await sink.close();
final prefs = await SharedPreferences.getInstance();
final later = new Duration(hours: 8));
prefs.setInt(NEXT_CACHE_UPDATE_EPOCH_KEY, later.millisecondsSinceEpoch);
setState(() {
_nextUpdate = new DateTime.fromMicrosecondsSinceEpoch(
later.millisecondsSinceEpoch * 1000);
_lastUpdate = new;
await prefs.commit();
catch (exception) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.