chips property
List<T>
get
chips
Returns an unmodifiable list of all chips in the controller.
Implementation
List<T> get chips => List.unmodifiable(_chipMap.values);
set
chips
(List<T> newChips)
Sets the chips in this controller, replacing all existing chips.
Implementation
set chips(List<T> newChips) {
String text = value.text;
// remove chips that are not in newChips
// add chips that are in newChips but not present, appending them at the last chip position
StringBuffer buffer = StringBuffer();
int chipCount = 0;
for (int i = 0; i < text.length; i++) {
int codeUnit = text.codeUnitAt(i);
if (codeUnit >= _chipStart && codeUnit <= _chipEnd) {
T? existingChip = _chipMap[codeUnit - _chipStart];
if (existingChip != null && newChips.contains(existingChip)) {
buffer.writeCharCode(codeUnit);
chipCount++;
}
} else {
buffer.writeCharCode(codeUnit);
}
}
for (int i = chipCount; i < newChips.length; i++) {
T chip = newChips[i];
int chipIndex = _nextAvailableChipIndex;
buffer.writeCharCode(_chipStart + chipIndex);
_chipMap[chipIndex] = chip;
}
super.value = value.copyWith(
text: buffer.toString(),
selection: TextSelection.collapsed(offset: buffer.length),
);
}