prefer_ asserts_ with_ message
Missing a message in an assert.
Description
#The analyzer produces this diagnostic when an assert statement doesn't have a message.
Example
#The following code produces this diagnostic because there's no message in the assert statement:
dart
void f(String s) {
assert(s.isNotEmpty);
}
Common fixes
#Add a message to the assert statement:
dart
void f(String s) {
assert(s.isNotEmpty, 'The argument must not be empty.');
}
Was this page's content helpful?
Thank you for your feedback!
Provide details
Thank you for your feedback!Please let us know what we can do to improve.
Provide details
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.