update method
- @override
- String input
override
Updates the value based on the user's input.
Perform validation here and set error accordingly. You do not have to set value in this function -- for example, if the user entered an invalid input.
Implementation
@override
void update(String input) {
if (input.isEmpty) {
error = "Empty";
} else if (double.tryParse(input) == null) {
error = "Invalid number";
} else if (isInteger && int.tryParse(input) == null) {
error = "Not an integer";
} else {
error = null;
final result = isInteger ? (int.parse(input) as T) : (double.parse(input) as T);
if (min != null && result < min!) error = "Must be >$min";
if (max != null && result > max!) error = "Must be <$max";
value = result;
}
notifyListeners();
}