LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

Type: ListSignalMixin

API reference and details for ListSignalMixin from signals.dart.

ListSignalMixin#

Kind: class  |  Package: package:signals_core

Class: ListSignalMixin#

A mixin that adds reactive List methods and operators to a Signal holding a List value.

This mixin delegates all standard List operations (such as mutations like add, remove, insert, sort, and clear, and accessor operators like [] and []=) to the underlying list, while ensuring that any reads register a dependency and any mutations automatically trigger reactive updates.

This mixin only works with signals that have a value type extending List.

Example Usage#

import 'package:signals/signals.dart';

class MyListSignal extends Signal<List<int>>
    with IterableSignalMixin<int, List<int>>, ListSignalMixin<int, List<int>> {
  MyListSignal(super.internalValue);
}

void main() {
  final numbers = MyListSignal([1, 2, 3]);

  effect(() {
    print('Elements: $numbers, Length: ${numbers.length}');
  }); // Prints: "Elements: [1, 2, 3], Length: 3"

  // Adding an element (automatically calls set() and triggers updates)
  numbers.add(4); // Prints: "Elements: [1, 2, 3, 4], Length: 4"

  // Modifying an element by index (triggers updates)
  numbers[0] = 10; // Prints: "Elements: [10, 2, 3, 4], Length: 4"
}
Since mutations on ListSignalMixin notify listeners automatically, you do not need to assign numbers.value = ... to force updates. Methods like add, addAll, and operator []= take care of notification.

Members of ListSignalMixin#

MemberTypeSignatureDescription
castmethoddart List cast()
firstmethoddart first(E val)
lastmethoddart E last
lastmethoddart last(E val)
lengthmethoddart length(int value)
+methoddart List +(List other)
[]methoddart E [](int index)
[]=methoddart void []=(int index, E value)
addmethoddart void add(E value)
addAllmethoddart void addAll(Iterable iterable)
asMapmethoddart Map<int, E> asMap()
clearmethoddart void clear()
expandmethoddart Iterable expand(Iterable Function(E element) toElements)
fillRangemethoddart void fillRange(int start, int end, [E? fillValue])
firstWheremethoddart E firstWhere(bool Function(E element) test, {E Function()? orElse})
foldmethoddart R fold(R initialValue, R Function(R previousValue, E element) combine)
followedBymethoddart Iterable followedBy(Iterable other)
getRangemethoddart Iterable getRange(int start, int end)
indexOfmethoddart int indexOf(E element, [int start = 0])
indexWheremethoddart int indexWhere(bool Function(E element) test, [int start = 0])
insertmethoddart void insert(int index, E element)
insertAllmethoddart void insertAll(int index, Iterable iterable)
lastIndexOfmethoddart int lastIndexOf(E element, [int? start])
lastIndexWheremethoddart int lastIndexWhere(bool Function(E element) test, [int? start])
removemethoddart bool remove(Object? value)
removeAtmethoddart E removeAt(int index)
removeLastmethoddart E removeLast()
removeRangemethoddart void removeRange(int start, int end)
removeWheremethoddart void removeWhere(bool Function(E element) test)
replaceRangemethoddart void replaceRange(int start, int end, Iterable replacements)
retainWheremethoddart void retainWhere(bool Function(E element) test)
reversedmethoddart Iterable reversed
setAllmethoddart void setAll(int index, Iterable iterable)
setRangemethoddart void setRange(int start, int end, Iterable iterable, [int skipCount = 0])
shufflemethoddart void shuffle([Random? random])
sortmethoddart void sort([int Function(E a, E b)? compare])
sortedmethoddart List sorted([int Function(E a, E b)? compare])Return a new array that is sorted by the compare function
sublistmethoddart List sublist(int start, [int? end])

References#

The ListSignalMixin type is referenced and used in the following pages: