3

Dart's assert function is not working for me for some reason.

It wasn't firing on my system

Dart VM version: 2.7.0 (Fri Dec 6 16:26:51 2019 +0100) on "windows_x64"

It isn't working on dartpad aswell.

Please look at this dartpad https://dartpad.dev/5352f91de86a0b3c58fdf6a8fb64a081.

image

4 Answers 4

7

This wasn't specific to dartpad as it wasn't running on my machine as well on dart 2.7.0. I was able to run it with the flag --enable-asserts

dart --enable-asserts lib\main.dart

Note:

The flag must be passed as dart --enable-asserts lib\main.dart but not dart lib\main.dart --enable-asserts as the second approach implies this flag is meant for lib\main.dart and not dart.

5

It appears that assert statements are disable in dartpad since July 2019, you can check the GitHub issue here https://github.com/dart-lang/dart-pad/issues/310#issuecomment-514068279

2

If you are running brief Dart programs often from the command line to test ideas, it's worth adding the following line to your .bash_profile, .zshrc:

alias dart="dart --enable-asserts"

or similar for other shells.

0

assert is not working on dartpad.dev either replit.com. I test it on 13 Oct 2021. So I used IntelliJ IDEA to work with assert and its working fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.