firstNotEqualTo method

  1. @useResult
String? firstNotEqualTo(
  1. String? value
)

Returns the first element that is not equal to value.

When value is null the comparison is skipped and the first element is returned (or null for an empty list). Comparison is case-sensitive, so firstNotEqualTo('a') does not match 'A'. Returns null when every element equals value, distinguishing "no differing element" from a real hit.

Example:

['a', 'a', 'b'].firstNotEqualTo('a'); // 'b'
['a', 'b'].firstNotEqualTo(null);     // 'a'
['a', 'a'].firstNotEqualTo('a');      // null

Audited: 2026-06-12 11:26 EDT

Implementation

@useResult
String? firstNotEqualTo(String? value) =>
    // The package:collection accessors return null instead of throwing when no
    // element qualifies, so an all-equal or empty list yields null cleanly.
    value == null ? firstOrNull : firstWhereOrNull((String item) => item != value);