/// Creates a list containing all [elements]. factory RxList.from(Iterable elements, {bool growable = true}) { return RxList(List.from(elements, growable: growable)); }
/// Creates a list from [elements]. factory RxList.of(Iterable<E> elements, {bool growable = true}) { return RxList(List.of(elements, growable: growable)); }
/// Generates a list of values. factory RxList.generate(int length, E generator(int index), {bool growable = true}) { return RxList(List.generate(length, generator, growable: growable)); }
/// Creates an unmodifiable list containing all [elements]. factory RxList.unmodifiable(Iterable elements) { return RxList(List.unmodifiable(elements)); }
@override Iterator<E> get iterator => value.iterator;
/// Special override to push() element(s) in a reactive way /// inside the List, @override RxList<E> operator +(Iterable<E> val) { addAll(val); refresh(); return this; }
@override E operator [](int index) { return value[index]; }
ListExtension<E> on List<E> { RxList<E> get obs => RxList<E>(this);
/// Add [item] to [List<E>] only if [item] is not null. void addNonNull(E item) { if (item != null) add(item); }
// /// Add [Iterable<E>] to [List<E>] only if [Iterable<E>] is not null. // void addAllNonNull(Iterable<E> item) { // if (item != null) addAll(item); // }
/// Add [item] to List<E> only if [condition] is true. void addIf(dynamic condition, E item) { if (condition is Condition) condition = condition(); if (condition is bool && condition) add(item); }
/// Adds [Iterable<E>] to [List<E>] only if [condition] is true. void addAllIf(dynamic condition, Iterable<E> items) { if (condition is Condition) condition = condition(); if (condition is bool && condition) addAll(items); }
/// Replaces all existing items of this list with [item] void assign(E item) { // if (this is RxList) { // (this as RxList)._value; // }
}
/// Replaces all existing items of this list with [items] void assignAll(Iterable<E> items) { // if (this is RxList) { // (this as RxList)._value; // } clear(); addAll(items); } } </pre>