Skip to content

Instantly share code, notes, and snippets.

@bobjackman
Last active January 8, 2018 21:59
Show Gist options
  • Save bobjackman/abdc0ecf00b60547b17b033cd0f5b010 to your computer and use it in GitHub Desktop.
Save bobjackman/abdc0ecf00b60547b17b033cd0f5b010 to your computer and use it in GitHub Desktop.
Title2
// DON'T DO THIS
if ((user != null && user.id.isNotEmpty && targetId == user.id) || (user.name.isNotEmpty ? user.name : '') == targetName || (phoneNumber.isNotEmpty && phoneNumber == user.phoneNumber)) {
  //...;
}

// DON'T DO THIS
if (
  (user != null && user.id.isNotEmpty && targetId == user.id)
  || (user.name.isNotEmpty ? user.name : '') == targetName
  || (phoneNumber.isNotEmpty && phoneNumber == user.phoneNumber)) {

  // <<=== remove one of the dots below and watch the highlighting change! (note thew new highlighting is still wrong (comments are highlighted as if they were code)
  //...;
  //...;    
}
  
// YES, DO THIS
var hasUser      = (user != null);
var isIdMatch    = (hasUser && user.id == targetId);
var isNameMatch  = ((user.name.isNotEmpty ? user.name : '') == targetName);
var isPhoneMatch = (phoneNumber.isNotEmpty && phoneNumber == user.phoneNumber);
  
if (isIdMatch || isNameMatch || isPhoneMatch) {
  //...;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment