How to fix Range Error(value): value not in range: 1 in flutter

On a flutter project where I use a textField to search for other users stored on my firestore database. After querying and getting the data. A message button shows where you can open a new chat room with the user.

class SearchPage extends StatefulWidget {
  @override
  _SearchPageState createState() => _SearchPageState();
}


class _SearchPageState extends State<SearchPage> {
  DataBaseMethods dataBaseMethods = DataBaseMethods();
  String searchText;
  QuerySnapshot searchSnapshot;

  Widget searchList() {
    return searchSnapshot != null
        ? ListView.builder(
            itemCount: searchSnapshot.docs.length,
            shrinkWrap: true,
            itemBuilder: (context, index) {
              return searchTile(
                userName: searchSnapshot.docs[index].data()['name'],
                userEmail: searchSnapshot.docs[index].data()['email']
              );
            },
          )
        : Container();
  }

  initiateSearch() {
    dataBaseMethods.getUserByUserName(searchText).then((val) {
      setState(() {
        print(val.toString());
        searchSnapshot = val;
      });
    });
  }

  //create ChatRoom, send user to game screen, pushReplacement
  createGameRoomAndStartGame({String userName}) {
    if (userName != Constants.myName) {
      String chatRoomId = getChatRoomId(userName, Constants.myName);

      List<String> users = [userName, Constants.myName];
      Map<String, dynamic> chatRoomMap = {
        'users': users,
        'chatRoomId': chatRoomId,
      };

      DataBaseMethods().createChatRoom(chatRoomId, chatRoomMap);
      Navigator.push(context,
          MaterialPageRoute(builder: (context) => GameScreen(chatRoomId)));
    } else {
      print('You cannot send a message to yourself');
    }
  }

  Widget searchTile({String userName, String userEmail}) {
    return Container(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Row(
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(userName ?? 'Error'),
                Text(userEmail ?? 'Error'),
              ],
            ),
            Spacer(),
            GestureDetector(
              onTap: () {
                createGameRoomAndStartGame(userName: userName);
              },
              child: Container(
                  decoration: BoxDecoration(
                      color: kSecondaryColor,
                      borderRadius: BorderRadius.circular(20)),
                  padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
                  child: Text('Request')),
            )
          ],
        ),
      ),
    );
  }

  @override
  void initState(){
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Search for player by username',
          style: GoogleFonts.pacifico(),
        ),
      ),
      body: Container(
        child: Column(
          children: [
            Container(
              color: kSecondaryColor,
              padding: EdgeInsets.symmetric(horizontal: 24, vertical: 16),
              child: Row(
                children: [
                  Expanded(
                    child: TextField(
                      onChanged: (val) {
                        searchText = val;
                      },
                      style: TextStyle(color: Colors.white),
                      decoration: InputDecoration(
                          hintText: 'Search Username...',
                          hintStyle: TextStyle(color: Colors.white54),
                          border: InputBorder.none),
                    ),
                  ),
                  GestureDetector(
                    onTap: (){
                      initiateSearch();
                    },
                    child: Container(
                        height: 40,
                        width: 40,
                        decoration: BoxDecoration(
                            gradient: LinearGradient(colors: [
                              const Color(0x36FFFFFF),
                              const Color(0x0FFFFFFF),
                            ]),
                            borderRadius: BorderRadius.circular(10)),
                        padding: EdgeInsets.all(12),
                        child: Icon(Icons.search)),
                  ),
                ],
              ),
            ),
            searchList(),
          ],
        ),
      ),
    );
  }
}
getChatRoomId(String a, String b) {
    if (a.substring(0, 1).codeUnitAt(0) > b.substring(0, 1).codeUnitAt(0)) {
      return "$b\_$a";
    } else {
      return "$a\_$b";
    }
}

All worked fine till the point where I am to click the message button. then a rangeError(value) 'value not in range: 1' basing the error on the getChatRoomId. This was an unusual error as there is very little help documentation as almost all common range errors are rangeError(index) and flutter documentation about RangeError.value is this.

However, running the code flutter pub upgrade fixed this error for me. I, therefore, believe this is a framework error.