/// ID发号器
class IDGenerator {
  int _lastNo = 0;

  /// 前缀
  final String? prefix;

  /// 数字部分最小长度
  final int numberMinLength;

  IDGenerator({
    this.prefix,
    this.numberMinLength = 4,
  });

  /// 生成新ID
  String generate() {
    final no = ++_lastNo;
    final noStr = no.toString().padLeft(numberMinLength, '0');
    if (prefix != null && prefix!.isNotEmpty) {
      return "$prefix$noStr";
    } else {
      return noStr;
    }
  }
}
