next_available_name 1.0.1 copy "next_available_name: ^1.0.1" to clipboard
next_available_name: ^1.0.1 copied to clipboard

Get next available name.

example/next_available_name_example.dart

import 'package:next_available_name/next_available_name.dart';

void main() async {
  // Use a set to track names that have been taken.
  Set<String> namesTaken = {'liu', 'zheng', 'liu (2)'};

  var nextNames = ['zheng', 'wang', 'liu'];
  var maxAttempts = 100;
  for (var name in nextNames) {
    var assigned = await nextAvailableName(
        name, maxAttempts, (name) async => !namesTaken.contains(name));
    print('$name -> $assigned');
  }
  /**
   * Prints:
   * zheng -> zheng (2)
   * wang -> wang
   * liu -> liu (3)
   */
}