Flutter Platform - ocd in platform order

Viewed 14

Pardon the ocd, but how do you choose who to write first in the if?

// Is mobile
if (Platform.isAndroid || Platform.isIOS) {
    
}

‍♂️

1 Answers

In this case it doesn't matter. It's however you like it. But keep in mind that they are evaluated left to right, so it might matter in other cases like:

if (objectWithName == null || objectWithName.name == null) {
  
}

If you write it like this instead

if (objectWithName.name == null || objectWithName == null) {
  
}

then the program would crash when objectWithName is null because then it tries to access objectWithName.name on a null object. With the first example it doesn't even consider the second condition because the first condition is already true

Related