attributeChangedCallback method

void attributeChangedCallback(
  1. String name,
  2. String? oldValue,
  3. String? newValue
)

Called when an observed attribute changes.

Override this method to react to attribute changes at runtime. This is called:

  • For each observed attribute with a value during hydration (before onMount)

  • Whenever an observed attribute is added, changed, or removed

  • name: The attribute name that changed

  • oldValue: The previous value (null if attribute was added)

  • newValue: The new value (null if attribute was removed)

Example

@override
void attributeChangedCallback(String name, String? oldValue, String? newValue) {
  switch (name) {
    case 'disabled':
      _updateDisabledState(newValue != null);
    case 'count':
      _updateCount(int.tryParse(newValue ?? '') ?? 0);
  }
}

Implementation

void attributeChangedCallback(
  String name,
  String? oldValue,
  String? newValue,
) {}