Skip to main content

empty_container_bodies

Details about the 'empty_container_bodies' diagnostic produced by the Dart analyzer.

Empty {0} bodies should be written using a ';' rather than '{}'.

Description

#

The analyzer produces this diagnostic when the block body of a class, enum, extension, extension type, or mixin is empty and can be replaced by a semicolon.

Example

#

The following code produces this diagnostic because the body of the class C is empty:

dart
class C {}

Common fixes

#

If the class needs to have members, then add them:

dart
class C {
  String toString() => 'c';
}

Otherwise, replace the body with a semicolon:

dart
class C;