Blasanka
Blasanka

Reputation: 22437

What is meant by ?? in Dart

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;

Upvotes: 3

Views: 409

Answers (1)

Blasanka
Blasanka

Reputation: 22437

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

Upvotes: 5

Related Questions