Flutter-Accumulator

内置累加整型计数器。初始值为0

官方源码如下:

class Accumulator {
  /// [Accumulator] may be initialized with a specified value, otherwise, it will
  /// initialize to zero.
  Accumulator([this._value = 0]);

  /// The integer stored in this [Accumulator].
  int get value => _value;
  int _value;

  /// Increases the [value] by the `addend`.
  void increment(int addend) {
    assert(addend >= 0);
    _value += addend;
  }
}

例子:

    final num = Accumulator();
    num.increment(10);
    if (kDebugMode) {
      print(num.value);
    }
    num.increment(8);
    if (kDebugMode) {
      print(num.value);
    }

输入结果为10、18

你可能感兴趣的:(Flutter-Accumulator)