我看到了类似以下示例代码:
class ModelBinding extends StatefulWidget {
ModelBinding({
Key key,
this.initialModel = const GalleryOptions(),
this.child,
}) : assert(initialModel != null),
super(key: key);
...
所以我写了一些东西:
class Person {
String firstName;
Person({name}){
print(name);
}
}
class Employee extends Person {
Employee(String name) : assert(false), super(name: name);
}
main() {
var emp = new Employee('Jason');
}
无论assert(false)或assert(true),结果都是相同的。
那么assert的含义是什么
谢谢
assert
is used for debugging and it simply means the condition should betrue
to proceed. Let me explain:You might face issues in
someMethod
ifage
passed isnull
, so to make sure it isn'tnull
, you useassert
like: