美文网首页
Flutter-Accumulator

Flutter-Accumulator

作者: ROB_YONG | 来源:发表于2022-06-28 18:43 被阅读0次

    内置累加整型计数器。初始值为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

          本文链接:https://www.haomeiwen.com/subject/cyhzvrtx.html