uploadLocalChanges method
synchronizes all local changes to the server Returns a list of local changes that were discarded because of optimistic conflict
Implementation
Future<bool> uploadLocalChanges() async {
final localChanges = await appDatabase.getPendingLocalChanges();
for (final localChange in localChanges) {
if (_state.cancelRequested) {
break;
}
final handler = _getTypeHandlerByTypeName(localChange.entityType);
try {
await this.appDatabase.transaction(() async {
await appDatabase.concludeLocalChange(localChange);
await _doOperation(localChange, handler);
});
} on UnavailableException catch (_) {
// in case we couldn't reach the server, let's just quit here and
// report we aren't able to continue
return false;
} catch (ex) {
// in case the server reported some error, let's register
// that and continue with the other local changes.
await appDatabase.concludeLocalChange(localChange, error: ex);
}
}
// concluded everything
return true;
}