The Validate Methods
@override
Option<WeatherHabitableFailure> validateHabitable(weather) {
// [temperature] is a shared property, so we can directly access it
// from [weather] :
final temperature = weather.temperature;
if (temperature > 60) {
return some(const WeatherHabitableFailure.tooHot());
}
if (temperature < -10) {
return some(const WeatherHabitableFailure.tooCold());
}
// You can use the case-modddels pattern matching methods on [weather] :
return weather.maybeMapWeather(
rainy: (rainy) => rainy.rainIntensity > 2.5
? some(const WeatherHabitableFailure.flooding())
: none(),
orElse: () => none(),
);
}Last updated