current property Null safety

String current

Implementation

String get current {
  if (model.isFloatMode) {
    if (_current.startsWith('-')) {
      return _current;
    } else {
      return ' $_current';
    }
  } else if (model.settings.windowEnabled) {
    final int maxWindow = ((_numDigits - 1) ~/ 8) * 8;
    if (_window > maxWindow) {
      _window = maxWindow;
      // If, for example, the base changed out from under us, like in
      // https://github.com/zathras/jrpn/issues/12
    }
    final int window = (_showingX) ? _window : 0;
    final int count = _numDigits;
    if (count <= 8) {
      return _current;
    }
    String radix = _current.substring(_current.length - 1);
    String r = _current.substring(0, _current.length - 2);

    final bool negative = r.startsWith('-');
    if (negative) {
      r = r.substring(1);
    }
    final List<int> digitPos = _allDigits
        .allMatches(r)
        .fold(List<int>.empty(growable: true), (List<int> l, RegExpMatch m) {
      l.add(m.start);
      return l;
    });
    assert(digitPos[0] == 0);
    final int end = 1 + digitPos[digitPos.length - 1 - window];
    final int start = digitPos[max(0, digitPos.length - 8 - window)];

    r = r.substring(start, end);
    final dot = (model.settings.euroComma ? ',' : '.');
    if (window < maxWindow) {
      // Dot before radix letter
      radix = dot + radix;
    }
    if (window > 0) {
      // Dot after radix letter
      radix = radix + dot;
    }
    if (negative && window >= maxWindow) {
      return '-$r $radix';
    } else {
      return '$r $radix';
    }
  } else {
    return _current;
  }
}
void current=(String v)

Implementation

set current(String v) {
  _current = v;
  _showingX = false;
}