2

I am looking at some Flutter projects and I notice this codes:

  @override
  int get hashCode => todos.hashCode ^ isLoading.hashCode;

What is this ^ sign doing here? This line of code is found in the AppState of Flutter projects. Is this used to compare the before and after State?

JOHN
  • 871
  • 1
  • 12
  • 24
  • This doesn't technically relate to your question, but I would recommend using `hashValues` from `dart:ui` instead of xor for custom hashCodes. See this answer for more details why https://stackoverflow.com/questions/263400/what-is-the-best-algorithm-for-an-overridden-system-object-gethashcode/263416#263416 – Jonah Williams May 03 '18 at 04:42

2 Answers2

5

It is the bitwise XOR operator

https://www.dartlang.org/guides/language/language-tour#operators

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

Below is the way to use XOR operator. I think this is not useful to you but it is helpful to some one who searching for XOR operation

Call below method encryptDecrypt("123456") . you will get output as abcdef

    String encryptDecrypt(String input) {
    int xorKey = "P".codeUnitAt(0);
    String output = "";
    int length = input.length;
    for (int i = 0; i < length; i++) {
      output = (output + String.fromCharCode((input[i].codeUnitAt(0) ^ xorKey)));
    }
    return output;
  }
Teja
  • 787
  • 7
  • 21