Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ?. do in Dart?

What does "?." syntax do in Dart language? I have here an example from Flutter's scaffold.dart code:

_drawerKey.currentState?.open();
like image 387
Landon Avatar asked Mar 04 '23 02:03

Landon


1 Answers

It's a null safe operator.

Use ?. when you want to call a method/getter on an object IF that object is not null (otherwise, return null).

_drawerKey.currentState?.open();

Call open() only if it's not null.

More info: https://medium.com/@thinkdigitalsoftware/null-aware-operators-in-dart-53ffb8ae80bb

like image 110
Kent Avatar answered Mar 05 '23 14:03

Kent