1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

veggieseasons: Migrate to null safety (#922)

This commit is contained in:
Brett Morgan
2021-10-12 10:27:54 +11:00
committed by GitHub
parent 994cdb4afa
commit ac2bef7d83
21 changed files with 134 additions and 148 deletions

View File

@@ -26,22 +26,22 @@ class AppState extends ChangeNotifier {
return _veggies.where((v) => !v.seasons.contains(currentSeason)).toList();
}
Veggie getVeggie(int id) => _veggies.singleWhere((v) => v.id == id);
Veggie getVeggie(int? id) => _veggies.singleWhere((v) => v.id == id);
List<Veggie> searchVeggies(String terms) => _veggies
.where((v) => v.name.toLowerCase().contains(terms.toLowerCase()))
List<Veggie> searchVeggies(String? terms) => _veggies
.where((v) => v.name.toLowerCase().contains(terms!.toLowerCase()))
.toList();
void setFavorite(int id, bool isFavorite) {
void setFavorite(int? id, bool isFavorite) {
var veggie = getVeggie(id);
veggie.isFavorite = isFavorite;
notifyListeners();
}
/// Used in tests to set the season independent of the current date.
static Season debugCurrentSeason;
static Season? debugCurrentSeason;
static Season _getSeasonForDate(DateTime date) {
static Season? _getSeasonForDate(DateTime date) {
if (debugCurrentSeason != null) {
return debugCurrentSeason;
}