updateAsLocal method

  1. @override
Future<bool> updateAsLocal({
  1. required String id,
  2. Map<String, dynamic> creates = const {},
  3. Map<String, dynamic> updates = const {},
  4. 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;
  }
}