1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Avoid app blocking

This commit is contained in:
Pierre HUBERT 2021-04-13 19:01:26 +02:00
parent 862401755d
commit cc760c5a24

View File

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:comunic/constants.dart'; import 'package:comunic/constants.dart';
import 'package:comunic/utils/flutter_utils.dart'; import 'package:comunic/utils/flutter_utils.dart';
import 'package:comunic/utils/log_utils.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
@ -54,7 +55,8 @@ abstract class BaseSerializationHelper<T extends SerializableElement> {
_cache.sort(); _cache.sort();
} catch (e, s) { } catch (e, s) {
print("Failed to read serialized data! $e => $s"); logError(e, s);
print("Failed to read serialized data!");
_cache = []; _cache = [];
} }
} }
@ -63,9 +65,14 @@ abstract class BaseSerializationHelper<T extends SerializableElement> {
Future<void> _saveCache() async { Future<void> _saveCache() async {
if (isWeb) return; if (isWeb) return;
final file = await _getFilePath(); try {
await file.writeAsString(jsonEncode( final file = await _getFilePath();
_cache.map((e) => e.toJson()).toList().cast<Map<String, dynamic>>())); await file.writeAsString(jsonEncode(
_cache.map((e) => e.toJson()).toList().cast<Map<String, dynamic>>()));
} catch (e, s) {
print("Failed to write file!");
logError(e, s);
}
} }
/// Get the current list of elements /// Get the current list of elements