Reputation:
here is an excerpt from my code containing the assertion
assert(age<30,'age must be less than 30');
Now, How to enable this assertion?
Upvotes: 2
Views: 2257
Reputation: 1359
Use the --enable-asserts
flag:
dart --enable-asserts file_name.dart
Upvotes: 4
Reputation: 89995
assert
s are enabled in debug builds of Flutter apps. They are not enabled in release builds.
If you need to check conditions in release builds, assert
s are inappropriate: assert
s are intended as sanity-checks to identify logical errors (i.e., mistakes in the code), not to catch runtime errors (e.g. unexpected input from the users).
Also see: why the assert function was disabled in dart?
Upvotes: 1