autoIncrement top-level property Null safety

Id Function() autoIncrement
final

Auto increment

Example:

final Id nextId = autoIncrement();
final Id testId = autoIncrement();

print(nextId()); // 1
print(nextId()); // 2
print(testId()); // 1
print(nextId()); // 3

Implementation

final Id Function() autoIncrement = () {
  int id = 0;
  return () => ++id;
};