user14114698
user14114698

Reputation:

How to enable assertions in dart?

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

Answers (2)

Julien Reszka
Julien Reszka

Reputation: 1359

Use the --enable-asserts flag:

dart --enable-asserts file_name.dart

Upvotes: 4

jamesdlin
jamesdlin

Reputation: 89995

asserts are enabled in debug builds of Flutter apps. They are not enabled in release builds.

If you need to check conditions in release builds, asserts are inappropriate: asserts 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

Related Questions