Search⌘ K
AI Features

Booleans

Explore how Dart's bool data type represents true and false values, including naming conventions, type inference, and nullable booleans. Understand the role of booleans in conditional logic to build clear and maintainable Dart applications.

Dart uses the bool data type to represent boolean values. A boolean has only two possible values: true and false.

We can think of a boolean like a basic light switch. The switch is either completely ON (true) or completely OFF (false). There is no in-between state.

To create a boolean variable, we use the bool keyword and assign it one of these two literal values.

Dart
void main() {
bool isRunning = true;
print(isRunning);
}
  • Lines 1–4: We define our main function as the entry point for the code.

  • Line 2: We declare a variable named isRunning of type bool and assign it an initial value of true.

  • Line 3: We print the value of isRunning to the console. The program outputs the word true.

It is helpful to note that while the ...