updateAsLocal method
Future<bool>
updateAsLocal({
- required String id,
- Map<
String, dynamic> creates = const {}, - Map<
String, dynamic> updates = const {}, - bool updateMode = false,
override
Implementation
@override
Future<bool> updateAsLocal({
required String id,
Map<String, dynamic> creates = const {},
Map<String, dynamic> updates = const {},
bool updateMode = false,
}) async {
if (id.isEmpty) return false;
try {
if (updateMode) {
if (updates.isNotEmpty) {
return onUpdateUser(id, updates).then((_) {
return onFetchUser(id).then((value) {
return repository.set(value);
});
});
} else {
return false;
}
} else {
return onFetchUser(id).then((remote) {
if (remote != null) {
if (updates.isNotEmpty) {
return onUpdateUser(id, updates).then((_) {
return onFetchUser(id).then((value) {
return repository.set(value);
});
});
} else {
return false;
}
} else {
final user = build(creates);
return onCreateUser(user).then((_) {
return repository.set(user);
});
}
});
}
} catch (_) {
return false;
}
}