此代码来自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");
}