0

I want to generate a unique id for my chat application. (Chat between flutter app and angular web)

This is my dart code...

   String peerId = widget.peerid; //some string value as ID
    String currentUserId = widget.currentId; //some string value as ID

    if (currentUserId.hashCode <= peerId.hashCode) {
      ChatId = '$currentUserId-$peerId';
    } else {
      ChatId = '$peerId-$currentUserId';
    }
    print(ChatId);

From this I am generating a chatid. I want to do the same for my web app end chat room. How can I generate the similar chatId as I generated in dart?

Ilthizam Imtiyas
  • 160
  • 1
  • 6
  • 17
  • Why don't you implement the one that Java uses? The pretty standard odd-prime (31) one. https://stackoverflow.com/questions/15518418/whats-behind-the-hashcode-method-for-string-in-java – Richard Heap Dec 18 '19 at 17:37
  • Maybe you should find an alternative that does not rely on hashCode – Rémi Rousselet Dec 18 '19 at 17:58

1 Answers1

0

UUID might help you to generate similar kinds of ids

For dart: https://pub.dev/packages/uuid

and

for typescript: https://www.npmjs.com/package/@types/uuid

SSVernekar
  • 81
  • 5