Booleans in Dart

Published on 29 March 2020
Last Updated on 29 March 2020

What are Booleans

Dart has a built in Data type named boolean that can be used for storing boolean literals true and false.

Boolean literals true and false are both a compile time constants.

Booleans can be stored into a variable as shown in the example given below:

How to use Booleans in Dart

Booleans can be used as shown in the program give below.

main(List<String> args) {
  var boolA = true;
  print('boolA is ${boolA}');

  var boolB = false;
  print('boolB is ${boolB}');

  var someBool;
  someBool = 2 > 1;
  print('someBool is ${someBool}');

Above program produces following output:

boolA is true
boolB is false
someBool is true