gpt4 book ai didi

flutter - 什么是 flutter 中的 "?."运算符

转载 作者:行者123 更新时间:2023-12-03 03:08:44 24 4
gpt4 key购买 nike

我正在使用图书馆,并且在很多地方?。
使用了运算符,我无法理解它的用途。

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();

最佳答案

?. [Conditional member access] - Like ., but the leftmost operand can be null; example: foo?.bar selects property bar from expression foo unless foo is null (in which case the value of foo?.bar is null)

from Dart Language Tour (Other Operators)



TLDR:它只是一个 null在访问成员(member)之前检查。如果运算符的左侧不为空,则它的工作方式简单地为 .如果是 null值(value)那么整个事情是 null .

在您的示例中: _debounceTimer?.isActive - 如果 _debounceTimer为空然后 _debounceTimer?.isActive <-> null如果 _debounceTimer不为空然后 _debounceTimer?.isActive <-> _debounceTimer.isActive .

同时检查: Dart Language tour (Conditional Expressions)???运算符(operator)。

关于flutter - 什么是 flutter 中的 "?."运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60294425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com