Kri*_*hna 3 timer operator-keyword dart flutter
我正在使用图书馆,并且在很多地方?。使用了运算符,我无法理解它的用途。
Timer _debounceTimer;
@override
initState() {
_textController.addListener(() {
// We debounce the listener as sometimes the caret position is updated after the listener
// this assures us we get an accurate caret position.
if (_debounceTimer?.isActive ?? false) _debounceTimer.cancel();
Run Code Online (Sandbox Code Playgroud)
?.[条件成员访问] - 类似.,但最左边的操作数可以是null; 示例:从表达式中foo?.bar选择属性bar,foo除非foo是null(在这种情况下,值为foo?.bar空)
TLDR:它只是null在访问成员之前进行检查。如果运算符的左侧不为 null,则它的工作方式很简单.,如果它是nullvalue,则整个事情都是null.
在您的示例中:_debounceTimer?.isActive- 如果_debounceTimer为空则_debounceTimer?.isActive<-> null,如果_debounceTimer不为空则_debounceTimer?.isActive<-> _debounceTimer.isActive。
还要检查:Dart Language tour (Conditional Expressions) for ??and ?operator。