Home > Software design >  What is the correct dart syntax?
What is the correct dart syntax?

Time:01-26

How do I do this in dart syntax, how do you read it? The value must be between 3 to 20 characters

Following does not work:

validator: (value) {
                    return value != null &&
                           value.length < 3 &&
                           value.length > 20
                        ? "Title between 3 ~ 20 characters"
                        : null;
                    }
validator: (value) {
    return value != null &&
          value.length > 10 &&
          value is int
      ? "Number to big"
      : null;
},

Following does work but only for less than 3 chars:

validator: (value) {
                    return value != null &&
                           value.length < 3 
                        ? "Title between 3 ~ 20 characters"
                        : null;
                    }

CodePudding user response:

value length > 3 and value length < 20 if it's true null(valid) else return message "Title between 3 ~ 20 characters"

validator: (value) {
     return value!=null && value.length > 3 && value.length < 20
          ? null
          : "Title between 3 ~ 20 characters";
    },
  • Related