list_ext.dart 275 Bytes


extension ListExtension<E> on List<E> {
  /// 获取数组中第一个匹配元素的index,没有就返回null
  int? indexWhereOrNull(bool Function(E element) test) {
    for (int i = 0; i < length; i++) {
      if (test(this[i])) return i;
    }
    return null;
  }
}