rowNotifier method

ValueNotifier<T?> rowNotifier(
  1. dynamic primaryKey
)

Returns a ValueNotifier that fires only when the row with this primaryKey changes. Fires when the row's value changes per == — a server touch that doesn't change any field is de-duplicated.

The notifier is cached per key: repeated calls with the same key return the same instance. When the last listener detaches, the notifier is disposed and removed from the cache on the next microtask; a subsequent rowNotifier(pk) call creates a fresh instance.

Only valid for tables with a declared primary key. Throws StateError on no-PK tables.

final entity = client.entity.rowNotifier(entityId);
entity.addListener(() => print('entity changed: ${entity.value}'));

Implementation

ValueNotifier<T?> rowNotifier(dynamic primaryKey) {
  if (!hasPrimaryKey) {
    throw StateError(
      'rowNotifier called on no-PK table "$tableName". '
      'Per-row notifiers require a declared primary key.',
    );
  }
  return _rowNotifiers.putIfAbsent(
    primaryKey,
    () => _AutoDisposeNotifier<T?>(
      _rowsByPrimaryKey[primaryKey],
      onEmpty: () => _removeRowNotifier(primaryKey),
    ),
  );
}