Reputation: 8448
I am trying to compare an input value to a list of items in Dart language, however, it does not seem to work.
Method:
String validateStoreNumber(String value) {
List<String> storeList = ['55', '56', '88'];
// String patttern = r'(^[a-zA-Z ]*$)';
RegExp regExp = new RegExp(r'^[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)$');
if (value.length == 0) {
return "car number is required";
} else if (!regExp.hasMatch(value)) {
return "Accepts only numbers";
} else if (value.length != 2){
return "car number must have 2 digits";
} else if (value != storeList.contains(value)){
return "Not our model";
}
return null;
}
Upvotes: 0
Views: 7219
Reputation: 1955
This line...
else if (value != storeList.contains(value))
Is the problem. The left side "value" is a string, and the right side "contains" is a boolean. You are comparing a string to a boolean.
I think you want this...
else if (!storeList.contains(value))
Upvotes: 4