I saw this operator in Example of Shared Preferences for Flutter plugin. And I didn't get it.
int counter = (prefs.getInt('counter') ?? 0) + 1;
I saw this operator in Example of Shared Preferences for Flutter plugin. And I didn't get it.
int counter = (prefs.getInt('counter') ?? 0) + 1;
It is called null-aware operator
Meaning, if and only if prefs.getInt('counter')
returns null
assign 0
to it and then increment by one.
Here, you can find a great blog post about null-aware operator: http://blog.sethladd.com/2015/07/null-aware-operators-in-dart.html