From af0858b69dde600f5ef001530d8df5db1313c022 Mon Sep 17 00:00:00 2001 From: Filip Hracek Date: Thu, 13 Aug 2020 13:55:11 -0700 Subject: [PATCH] Veggie seasons update (#518) --- MAINTENANCE.md | 2 +- veggieseasons/ios/Podfile | 77 +++++-------------- veggieseasons/ios/Podfile.lock | 14 +--- .../ios/Runner.xcodeproj/project.pbxproj | 5 ++ veggieseasons/lib/data/app_state.dart | 14 ++-- veggieseasons/lib/data/preferences.dart | 4 +- veggieseasons/lib/main.dart | 20 +++-- veggieseasons/lib/screens/details.dart | 8 +- veggieseasons/lib/screens/favorites.dart | 4 +- veggieseasons/lib/screens/list.dart | 8 +- veggieseasons/lib/screens/search.dart | 4 +- veggieseasons/lib/screens/settings.dart | 8 +- veggieseasons/lib/widgets/trivia.dart | 5 +- veggieseasons/pubspec.lock | 73 ++++++++++++++++-- veggieseasons/pubspec.yaml | 4 +- 15 files changed, 133 insertions(+), 117 deletions(-) diff --git a/MAINTENANCE.md b/MAINTENANCE.md index 95d7fe9fb..a410860ad 100644 --- a/MAINTENANCE.md +++ b/MAINTENANCE.md @@ -19,4 +19,4 @@ match any new language/SDK features, etc.). | provider_counter | redbrogdon | 11/21/19 | | provider_shopper | redbrogdon | 11/21/19 | | testing_app | | | -| veggieseasons | | | +| veggieseasons | filiph | 8/13/20 | diff --git a/veggieseasons/ios/Podfile b/veggieseasons/ios/Podfile index d0d1d3e14..1e8c3c90a 100644 --- a/veggieseasons/ios/Podfile +++ b/veggieseasons/ios/Podfile @@ -10,73 +10,32 @@ project 'Runner', { 'Release' => :release, } -def parse_KV_file(file, separator='=') - file_abs_path = File.expand_path(file) - if !File.exists? file_abs_path - return []; +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" end - generated_key_values = {} - skip_line_start_symbols = ["#", "/"] - File.foreach(file_abs_path) do |line| - next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } - plugin = line.split(pattern=separator) - if plugin.length == 2 - podname = plugin[0].strip() - path = plugin[1].strip() - podpath = File.expand_path("#{path}", file_abs_path) - generated_key_values[podname] = podpath - else - puts "Invalid plugin specification: #{line}" - end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches end - generated_key_values + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" end +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + target 'Runner' do use_frameworks! use_modular_headers! - # Flutter Pod - - copied_flutter_dir = File.join(__dir__, 'Flutter') - copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework') - copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec') - unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path) - # Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet. - # That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration. - # CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist. - - generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig') - unless File.exist?(generated_xcode_build_settings_path) - raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first" - end - generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path) - cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR']; - - unless File.exist?(copied_framework_path) - FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir) - end - unless File.exist?(copied_podspec_path) - FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir) - end - end - - # Keep pod path relative so it can be checked into Podfile.lock. - pod 'Flutter', :path => 'Flutter' - - # Plugin Pods + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end - # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock - # referring to absolute paths on developers' machines. - system('rm -rf .symlinks') - system('mkdir -p .symlinks/plugins') - plugin_pods = parse_KV_file('../.flutter-plugins') - plugin_pods.each do |name, path| - symlink = File.join('.symlinks', 'plugins', name) - File.symlink(path, symlink) - pod name, :path => File.join(symlink, 'ios') +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) end end - -# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. -install! 'cocoapods', :disable_input_output_paths => true diff --git a/veggieseasons/ios/Podfile.lock b/veggieseasons/ios/Podfile.lock index db1cdd426..4bffb078c 100644 --- a/veggieseasons/ios/Podfile.lock +++ b/veggieseasons/ios/Podfile.lock @@ -2,33 +2,21 @@ PODS: - Flutter (1.0.0) - shared_preferences (0.0.1): - Flutter - - shared_preferences_macos (0.0.1): - - Flutter - - shared_preferences_web (0.0.1): - - Flutter DEPENDENCIES: - Flutter (from `Flutter`) - shared_preferences (from `.symlinks/plugins/shared_preferences/ios`) - - shared_preferences_macos (from `.symlinks/plugins/shared_preferences_macos/ios`) - - shared_preferences_web (from `.symlinks/plugins/shared_preferences_web/ios`) EXTERNAL SOURCES: Flutter: :path: Flutter shared_preferences: :path: ".symlinks/plugins/shared_preferences/ios" - shared_preferences_macos: - :path: ".symlinks/plugins/shared_preferences_macos/ios" - shared_preferences_web: - :path: ".symlinks/plugins/shared_preferences_web/ios" SPEC CHECKSUMS: Flutter: 0e3d915762c693b495b44d77113d4970485de6ec shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d - shared_preferences_macos: f3f29b71ccbb56bf40c9dd6396c9acf15e214087 - shared_preferences_web: 141cce0c3ed1a1c5bf2a0e44f52d31eeb66e5ea9 -PODFILE CHECKSUM: 75bff59e97643485829cfc01124f2ea710a554fc +PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c COCOAPODS: 1.9.1 diff --git a/veggieseasons/ios/Runner.xcodeproj/project.pbxproj b/veggieseasons/ios/Runner.xcodeproj/project.pbxproj index 4abf3856b..6ad121895 100644 --- a/veggieseasons/ios/Runner.xcodeproj/project.pbxproj +++ b/veggieseasons/ios/Runner.xcodeproj/project.pbxproj @@ -225,9 +225,14 @@ files = ( ); inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", + "${PODS_ROOT}/../Flutter/Flutter.framework", + "${BUILT_PRODUCTS_DIR}/shared_preferences/shared_preferences.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/shared_preferences.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/veggieseasons/lib/data/app_state.dart b/veggieseasons/lib/data/app_state.dart index f19029cd0..53d0f7806 100644 --- a/veggieseasons/lib/data/app_state.dart +++ b/veggieseasons/lib/data/app_state.dart @@ -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 _veggies; AppState() : _veggies = LocalVeggieProvider.veggies; List get allVeggies => List.from(_veggies); - Veggie getVeggie(int id) => _veggies.singleWhere((v) => v.id == id); - List get availableVeggies { var currentSeason = _getSeasonForDate(DateTime.now()); return _veggies.where((v) => v.seasons.contains(currentSeason)).toList(); } + List get favoriteVeggies => + _veggies.where((v) => v.isFavorite).toList(); + List get unavailableVeggies { var currentSeason = _getSeasonForDate(DateTime.now()); return _veggies.where((v) => !v.seasons.contains(currentSeason)).toList(); } - List get favoriteVeggies => - _veggies.where((v) => v.isFavorite).toList(); + Veggie getVeggie(int id) => _veggies.singleWhere((v) => v.id == id); List searchVeggies(String terms) => _veggies .where((v) => v.name.toLowerCase().contains(terms.toLowerCase())) diff --git a/veggieseasons/lib/data/preferences.dart b/veggieseasons/lib/data/preferences.dart index dc67feb2a..01c345a85 100644 --- a/veggieseasons/lib/data/preferences.dart +++ b/veggieseasons/lib/data/preferences.dart @@ -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'; diff --git a/veggieseasons/lib/main.dart b/veggieseasons/lib/main.dart index 7234d2715..bd334ee3a 100644 --- a/veggieseasons/lib/main.dart +++ b/veggieseasons/lib/main.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart' show DeviceOrientation, SystemChrome; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/preferences.dart'; import 'package:veggieseasons/screens/home.dart'; @@ -17,14 +17,18 @@ void main() { ]); runApp( - ScopedModel( - model: AppState(), - child: ScopedModel( - model: Preferences()..load(), - child: CupertinoApp( - debugShowCheckedModeBanner: false, - home: HomeScreen(), + MultiProvider( + providers: [ + ChangeNotifierProvider( + create: (_) => AppState(), ), + ChangeNotifierProvider( + create: (_) => Preferences()..load(), + ), + ], + child: CupertinoApp( + debugShowCheckedModeBanner: false, + home: HomeScreen(), ), ), ); diff --git a/veggieseasons/lib/screens/details.dart b/veggieseasons/lib/screens/details.dart index cd8f2b2b4..1bcca04b7 100644 --- a/veggieseasons/lib/screens/details.dart +++ b/veggieseasons/lib/screens/details.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/preferences.dart'; import 'package:veggieseasons/data/veggie.dart'; @@ -163,8 +163,8 @@ class InfoView extends StatelessWidget { @override Widget build(BuildContext context) { - final appState = ScopedModel.of(context, rebuildOnChange: true); - final prefs = ScopedModel.of(context, rebuildOnChange: true); + final appState = Provider.of(context); + final prefs = Provider.of(context); final veggie = appState.getVeggie(id); final themeData = CupertinoTheme.of(context); @@ -280,7 +280,7 @@ class _DetailsScreenState extends State { @override Widget build(BuildContext context) { - final appState = ScopedModel.of(context, rebuildOnChange: true); + final appState = Provider.of(context); return CupertinoPageScaffold( child: Column( diff --git a/veggieseasons/lib/screens/favorites.dart b/veggieseasons/lib/screens/favorites.dart index d25dba813..f565c6be9 100644 --- a/veggieseasons/lib/screens/favorites.dart +++ b/veggieseasons/lib/screens/favorites.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/veggie.dart'; import 'package:veggieseasons/styles.dart'; @@ -15,7 +15,7 @@ class FavoritesScreen extends StatelessWidget { Widget build(BuildContext context) { return CupertinoTabView( builder: (context) { - final model = ScopedModel.of(context, rebuildOnChange: true); + final model = Provider.of(context); return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( diff --git a/veggieseasons/lib/screens/list.dart b/veggieseasons/lib/screens/list.dart index 48c202558..288ee1758 100644 --- a/veggieseasons/lib/screens/list.dart +++ b/veggieseasons/lib/screens/list.dart @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/preferences.dart'; import 'package:veggieseasons/data/veggie.dart'; @@ -32,10 +32,8 @@ class ListScreen extends StatelessWidget { builder: (context) { var dateString = DateFormat('MMMM y').format(DateTime.now()); - final appState = - ScopedModel.of(context, rebuildOnChange: true); - final prefs = - ScopedModel.of(context, rebuildOnChange: true); + final appState = Provider.of(context); + final prefs = Provider.of(context); final themeData = CupertinoTheme.of(context); return SafeArea( bottom: false, diff --git a/veggieseasons/lib/screens/search.dart b/veggieseasons/lib/screens/search.dart index 71ee151a1..986cfca30 100644 --- a/veggieseasons/lib/screens/search.dart +++ b/veggieseasons/lib/screens/search.dart @@ -4,7 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/veggie.dart'; import 'package:veggieseasons/styles.dart'; @@ -73,7 +73,7 @@ class _SearchScreenState extends State { @override Widget build(BuildContext context) { - final model = ScopedModel.of(context, rebuildOnChange: true); + final model = Provider.of(context); return CupertinoTabView( builder: (context) { diff --git a/veggieseasons/lib/screens/settings.dart b/veggieseasons/lib/screens/settings.dart index 9bea1f597..912840f03 100644 --- a/veggieseasons/lib/screens/settings.dart +++ b/veggieseasons/lib/screens/settings.dart @@ -5,7 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/preferences.dart'; import 'package:veggieseasons/data/veggie.dart'; import 'package:veggieseasons/styles.dart'; @@ -15,7 +15,7 @@ import 'package:veggieseasons/widgets/settings_item.dart'; class VeggieCategorySettingsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final model = ScopedModel.of(context, rebuildOnChange: true); + final model = Provider.of(context); final currentPrefs = model.preferredCategories; var brightness = CupertinoTheme.brightnessOf(context); return CupertinoPageScaffold( @@ -79,7 +79,7 @@ class CalorieSettingsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final model = ScopedModel.of(context, rebuildOnChange: true); + final model = Provider.of(context); var brightness = CupertinoTheme.brightnessOf(context); return CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( @@ -181,7 +181,7 @@ class SettingsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final prefs = ScopedModel.of(context, rebuildOnChange: true); + final prefs = Provider.of(context); return CupertinoPageScaffold( child: Container( diff --git a/veggieseasons/lib/widgets/trivia.dart b/veggieseasons/lib/widgets/trivia.dart index 734bf0345..11dcde679 100644 --- a/veggieseasons/lib/widgets/trivia.dart +++ b/veggieseasons/lib/widgets/trivia.dart @@ -1,6 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; -import 'package:scoped_model/scoped_model.dart'; +import 'package:provider/provider.dart'; import 'package:veggieseasons/data/app_state.dart'; import 'package:veggieseasons/data/veggie.dart'; import 'package:veggieseasons/styles.dart'; @@ -48,8 +48,7 @@ class _TriviaViewState extends State { void didChangeDependencies() { super.didChangeDependencies(); - final newAppState = - ScopedModel.of(context, rebuildOnChange: true); + final newAppState = Provider.of(context); setState(() { appState = newAppState; diff --git a/veggieseasons/pubspec.lock b/veggieseasons/pubspec.lock index 0ad8d11d3..fdf2bc5ad 100644 --- a/veggieseasons/pubspec.lock +++ b/veggieseasons/pubspec.lock @@ -85,6 +85,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter @@ -142,6 +149,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.8" + nested: + dependency: transitive + description: + name: nested + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.4" path: dependency: transitive description: @@ -149,6 +163,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.7.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1+2" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" pedantic: dependency: "direct dev" description: @@ -163,20 +191,48 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.4.0" - scoped_model: + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.13" + provider: dependency: "direct main" description: - name: scoped_model + name: provider url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "4.3.2" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.7+1" + version: "0.5.8" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.2+1" shared_preferences_macos: dependency: transitive description: @@ -259,6 +315,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0" xml: dependency: transitive description: @@ -275,4 +338,4 @@ packages: version: "2.2.1" sdks: dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.12.13+hotfix.5 <2.0.0" + flutter: ">=1.16.0 <2.0.0" diff --git a/veggieseasons/pubspec.yaml b/veggieseasons/pubspec.yaml index dc9596bd1..40a38dff0 100644 --- a/veggieseasons/pubspec.yaml +++ b/veggieseasons/pubspec.yaml @@ -13,8 +13,8 @@ dependencies: cupertino_icons: ^0.1.3 font_awesome_flutter: ^8.8.1 intl: ^0.16.1 - scoped_model: ^1.0.1 - shared_preferences: ^0.5.7 + provider: ^4.3.2 + shared_preferences: ^0.5.8 dev_dependencies: flutter_test: