1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-10 14:58:34 +00:00

Veggie seasons update (#518)

This commit is contained in:
Filip Hracek
2020-08-13 13:55:11 -07:00
committed by GitHub
parent e73b132ce5
commit af0858b69d
15 changed files with 135 additions and 119 deletions

View File

@@ -2,31 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:scoped_model/scoped_model.dart';
import 'package:veggieseasons/data/veggie.dart';
import 'package:flutter/foundation.dart';
import 'package:veggieseasons/data/local_veggie_provider.dart';
import 'package:veggieseasons/data/veggie.dart';
class AppState extends Model {
class AppState extends ChangeNotifier {
final List<Veggie> _veggies;
AppState() : _veggies = LocalVeggieProvider.veggies;
List<Veggie> get allVeggies => List<Veggie>.from(_veggies);
Veggie getVeggie(int id) => _veggies.singleWhere((v) => v.id == id);
List<Veggie> get availableVeggies {
var currentSeason = _getSeasonForDate(DateTime.now());
return _veggies.where((v) => v.seasons.contains(currentSeason)).toList();
}
List<Veggie> get favoriteVeggies =>
_veggies.where((v) => v.isFavorite).toList();
List<Veggie> get unavailableVeggies {
var currentSeason = _getSeasonForDate(DateTime.now());
return _veggies.where((v) => !v.seasons.contains(currentSeason)).toList();
}
List<Veggie> get favoriteVeggies =>
_veggies.where((v) => v.isFavorite).toList();
Veggie getVeggie(int id) => _veggies.singleWhere((v) => v.id == id);
List<Veggie> searchVeggies(String terms) => _veggies
.where((v) => v.name.toLowerCase().contains(terms.toLowerCase()))

View File

@@ -4,13 +4,13 @@
import 'dart:async';
import 'package:scoped_model/scoped_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:veggieseasons/data/veggie.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// A model class that mirrors the options in [SettingsScreen] and stores data
/// in shared preferences.
class Preferences extends Model {
class Preferences extends ChangeNotifier {
// Keys to use with shared preferences.
static const _caloriesKey = 'calories';
static const _preferredCategoriesKey = 'preferredCategories';