Skip to content

Instantly share code, notes, and snippets.

@ntatko
Created June 20, 2022 18:01
Show Gist options
  • Select an option

  • Save ntatko/6be8a4c4a4a79afe07583e48478d69d4 to your computer and use it in GitHub Desktop.

Select an option

Save ntatko/6be8a4c4a4a79afe07583e48478d69d4 to your computer and use it in GitHub Desktop.
Logical Operators in Dart example
/// LOGICAL OPERATORS
void main() {
// &&
bool first = (true) && (true); // true
bool second = (true) && (false); // false
List array = [1, 2, 3];
Map map = {};
bool theyAreBothEmpty = array.isEmpty && map.isEmpty; // false
bool theyAreBothNotEmpty = array.isNotEmpty && map.isNotEmpty; // false
bool thirdCase = array.isNotEmpty && map.isEmpty; // true
// ||
bool third = (false) || (false); // false
bool fourth = (true) || (false); // true
bool fifth = (true) || (true); // true
List array2 = [1, 2, 3];
Map map2 = {};
bool oneIsEmpty = array2.isEmpty || map2.isEmpty; // true
bool oneIsNotEmpty = array2.isNotEmpty || map2.isNotEmpty; // true
bool mixed = array2.isNotEmpty || map.isEmpty; // true
bool willBeFalse = array2.isEmpty || map2.isNotEmpty; // false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment