A string generator designed to enhance real-time editing of ordered sequences by making the process of reordering, sorting, and interleaving transactions more efficient.


  • between(String prev, String next).
    It generates a lexicographically ordered string between prev and next. The returned string is intended to be used as a sort key for some data.

    final mid = between(prev: 'B', next: 'D');
        [mid, 'D', 'B']..sort(),
        ['B', mid, 'D'],
  • generateOrderKeys(int keyCount).
    It generates a series of strings to serve as sorting keys for data.

    final keyCount = 100; 
    final orderKeys = generateOrderKeys(keyCount);

    Use cases:

    1. When 'between' is unsuitable due to an empty table or collection:

      Future<void> addTodo(CreateTodo command) async {
        final String orderKey = todos.isEmpty 
          ? generateOrderKeys(1).first // <==
          : between(prev: todos.last.orderKey);
        final todo = await todoRepository.create(command, orderKey);
    2. During migration to an efficient ordered system:

      Future<void> migrateToLexicalOrderSystem(Table table) async {
        final itemCount = table.count();
        final orderKeys = generateOrderKeys(itemCount);
        /* omitted */