What is meant by ?? in Dart

2019-07-20 03:16发布

问题:

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;

回答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



标签: dart