flutter - dart assert 声明的一个很好的解释
问题描述
此代码来自flutter
sdk。
我无法理解assert((){}())
的表情。
它来自setState()
功能。
assert(() {
if (result is Future) {
throw FlutterError(
'setState() callback argument returned a Future.\n'
'The setState() method on $this was called with a closure or method that '
'returned a Future. Maybe it is marked as "async".\n'
'Instead of performing asynchronous work inside a call to setState(), first '
'execute the work (without updating the widget state), and then synchronously '
'update the state inside a call to setState().'
);
}
// We ignore other types of return values so that you can do things like:
// setState(() => x = 3);
return true;
}());
我已经测试了下面的代码。
b
没有打印。
main() {
assert(() {
print("b");
} ());
print("a");
}
解决方案
推荐阅读
- python - seaborn clustermap 不会重新排列注释数据
- c# - 我如何反序列化标题名称为 ASP.Net Core 的 json 列表
- angular - NgRx:store.select 需要 RxJS 管道操作符吗?
- java - 将数字格式化为货币并存储为整数
- javascript - 如何隐藏javascript函数的值?
- python - VS Code Python 交互窗口找不到 Conda Env
- swift - `Control Click` 是否意味着与 macOS 的`右键单击` 相同?
- javascript - 基于日历中的用户输入,突出显示时间和星期几
- javascript - 找不到模块 'mongoose-unique-validator'
- c# - 从 Windows 服务调用 .bat