generatePushChildName static method

String generatePushChildName()

Implementation

static String generatePushChildName() {
  int now = DateTime.now().millisecondsSinceEpoch;
  final bool duplicateTime = (now == _lastPushTime);
  _lastPushTime = now;

  final List<String> timeStampChars = List.filled(8, '');
  for (int i = 7; i >= 0; i--) {
    timeStampChars[i] = PUSH_CHARS[now % 64];
    now = (now / 64).floor();
  }
  assert(now == 0);

  final StringBuffer result = StringBuffer(timeStampChars.join());

  if (!duplicateTime) {
    for (int i = 0; i < 12; i++) {
      _lastRandChars[i] = _random.nextInt(64);
    }
  } else {
    _incrementArray();
  }
  for (int i = 0; i < 12; i++) {
    result.write(PUSH_CHARS[_lastRandChars[i]]);
  }
  assert(result.length == 20);
  return result.toString();
}