Skip to content

Commit

Permalink
Veggie seasons update (flutter#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
filiph authored Aug 13, 2020
1 parent e73b132 commit af0858b
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 117 deletions.
2 changes: 1 addition & 1 deletion MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
77 changes: 18 additions & 59 deletions veggieseasons/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 1 addition & 13 deletions veggieseasons/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions veggieseasons/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions veggieseasons/lib/data/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
4 changes: 2 additions & 2 deletions veggieseasons/lib/data/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
20 changes: 12 additions & 8 deletions veggieseasons/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -17,14 +17,18 @@ void main() {
]);

runApp(
ScopedModel<AppState>(
model: AppState(),
child: ScopedModel<Preferences>(
model: Preferences()..load(),
child: CupertinoApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => AppState(),
),
ChangeNotifierProvider(
create: (_) => Preferences()..load(),
),
],
child: CupertinoApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
),
),
);
Expand Down
8 changes: 4 additions & 4 deletions veggieseasons/lib/screens/details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -163,8 +163,8 @@ class InfoView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final appState = ScopedModel.of<AppState>(context, rebuildOnChange: true);
final prefs = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
final appState = Provider.of<AppState>(context);
final prefs = Provider.of<Preferences>(context);
final veggie = appState.getVeggie(id);
final themeData = CupertinoTheme.of(context);

Expand Down Expand Up @@ -280,7 +280,7 @@ class _DetailsScreenState extends State<DetailsScreen> {

@override
Widget build(BuildContext context) {
final appState = ScopedModel.of<AppState>(context, rebuildOnChange: true);
final appState = Provider.of<AppState>(context);

return CupertinoPageScaffold(
child: Column(
Expand Down
4 changes: 2 additions & 2 deletions veggieseasons/lib/screens/favorites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,7 +15,7 @@ class FavoritesScreen extends StatelessWidget {
Widget build(BuildContext context) {
return CupertinoTabView(
builder: (context) {
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
final model = Provider.of<AppState>(context);

return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
Expand Down
8 changes: 3 additions & 5 deletions veggieseasons/lib/screens/list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,10 +32,8 @@ class ListScreen extends StatelessWidget {
builder: (context) {
var dateString = DateFormat('MMMM y').format(DateTime.now());

final appState =
ScopedModel.of<AppState>(context, rebuildOnChange: true);
final prefs =
ScopedModel.of<Preferences>(context, rebuildOnChange: true);
final appState = Provider.of<AppState>(context);
final prefs = Provider.of<Preferences>(context);
final themeData = CupertinoTheme.of(context);
return SafeArea(
bottom: false,
Expand Down
4 changes: 2 additions & 2 deletions veggieseasons/lib/screens/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -73,7 +73,7 @@ class _SearchScreenState extends State<SearchScreen> {

@override
Widget build(BuildContext context) {
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
final model = Provider.of<AppState>(context);

return CupertinoTabView(
builder: (context) {
Expand Down
8 changes: 4 additions & 4 deletions veggieseasons/lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,7 +15,7 @@ import 'package:veggieseasons/widgets/settings_item.dart';
class VeggieCategorySettingsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final model = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
final model = Provider.of<Preferences>(context);
final currentPrefs = model.preferredCategories;
var brightness = CupertinoTheme.brightnessOf(context);
return CupertinoPageScaffold(
Expand Down Expand Up @@ -79,7 +79,7 @@ class CalorieSettingsScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final model = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
final model = Provider.of<Preferences>(context);
var brightness = CupertinoTheme.brightnessOf(context);
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
Expand Down Expand Up @@ -181,7 +181,7 @@ class SettingsScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
final prefs = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
final prefs = Provider.of<Preferences>(context);

return CupertinoPageScaffold(
child: Container(
Expand Down
5 changes: 2 additions & 3 deletions veggieseasons/lib/widgets/trivia.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -48,8 +48,7 @@ class _TriviaViewState extends State<TriviaView> {
void didChangeDependencies() {
super.didChangeDependencies();

final newAppState =
ScopedModel.of<AppState>(context, rebuildOnChange: true);
final newAppState = Provider.of<AppState>(context);

setState(() {
appState = newAppState;
Expand Down
Loading

0 comments on commit af0858b

Please sign in to comment.