有一个ChangeNotifierList吗?

时间:2019-08-02 15:37:01

标签: flutter dart flutter-provider

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

1 个答案:

答案 0 :(得分: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();
  }
}