updateCell method

  1. @override
Future<void> updateCell(
  1. String collection,
  2. String column,
  3. Object? newValue,
  4. Map<String, dynamic> row,
)
override

Perbarui nilai satu sel. Implementasi spesifik per engine.

Implementation

@override
Future<void> updateCell(
  String collection,
  String column,
  Object? newValue,
  Map<String, dynamic> row,
) async {
  final key = row['key'] as String?;
  final expectedType = row['type'] as String?;

  if (column == 'type') {
    throw ArgumentError('Cannot change the type field (expected "$expectedType").');
  }

  if (column == 'key') {
    if (key == null || newValue is! String || newValue.isEmpty) {
      throw ArgumentError('Invalid key value.');
    }
    final currentValue = _preferences.get(key);
    final typeName = expectedType ?? _typeName(currentValue);
    await _preferences.remove(key);
    await _setValue(newValue, currentValue, typeName);
    return;
  }

  if (column != 'value') {
    throw UnsupportedError('Only key and value columns can be edited.');
  }

  if (key == null) throw ArgumentError('Row has no key.');

  if (expectedType != null && !_valueMatchesType(newValue, expectedType)) {
    throw ArgumentError(
      'Value must remain $expectedType (got ${_describeValueType(newValue)}).',
    );
  }

  final typeName = expectedType ?? _typeName(newValue);
  await _setValue(key, newValue, typeName);
}