0

是否有实现 ChangeNotifier 的 List 类?基本上,如果将任何内容添加到列表或重新排列列表,它将调用 notifyListeners?

4

1 回答 1

1

不,但这里有一个:

class ChangeNotifierList<T> with ListMixin<T>, ChangeNotifier {
  ChangeNotifierList(this._internalList);

  final List<T> _internalList;

  @override
  int get length => _internalList.length;

  @override
  T operator [](int index) {
    return _internalList[index];
  }

  @override
  void operator []=(int index, T value) {
    _internalList[index] = value;
    notifyListeners();
  }

  @override
  set length(int newLength) {
    _internalList.length = newLength;
    notifyListeners();
  }
}
于 2019-08-02T15:43:50.657 回答