Member-only story
Assert in Dart
The assert statement in Dart is used to verify conditions that should always be true during development. If the condition fails (evaluates to false), Dart throws an AssertionError. This helps catch bugs early before they cause serious issues.
Read Medium Story for free 👇
Dart Assert Syntax:
assert(condition, [optionalMessage]);- condition: A boolean expression that should evaluate to true.
- • optionalMessage (optional): A message displayed if the assertion fails.
Important Notes:
- Assertions only work in debug mode. In release mode, they are ignored.
- They are useful for debugging but should not be relied upon for error handling in production.
Examples of assert in Dart
1. Basic Assertion
void main() {
int age = 25;
assert(age > 0, 'Age must be greater than zero');
print('Assertion passed!');
}









