mirror of https://github.com/flutter/samples.git
Adds veggieseasons preferences, tweaks styles + list page (#37)
parent
60837792a1
commit
2a2c535aab
@ -1 +1,2 @@
|
||||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||
#include "Generated.xcconfig"
|
||||
|
@ -1 +1,2 @@
|
||||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||
#include "Generated.xcconfig"
|
||||
|
@ -0,0 +1,69 @@
|
||||
# Uncomment this line to define a global platform for your project
|
||||
# platform :ios, '9.0'
|
||||
|
||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||
|
||||
project 'Runner', {
|
||||
'Debug' => :debug,
|
||||
'Profile' => :release,
|
||||
'Release' => :release,
|
||||
}
|
||||
|
||||
def parse_KV_file(file, separator='=')
|
||||
file_abs_path = File.expand_path(file)
|
||||
if !File.exists? file_abs_path
|
||||
return [];
|
||||
end
|
||||
pods_ary = []
|
||||
skip_line_start_symbols = ["#", "/"]
|
||||
File.foreach(file_abs_path) { |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)
|
||||
pods_ary.push({:name => podname, :path => podpath});
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
}
|
||||
return pods_ary
|
||||
end
|
||||
|
||||
target 'Runner' do
|
||||
# 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')
|
||||
|
||||
# Flutter Pods
|
||||
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
|
||||
if generated_xcode_build_settings.empty?
|
||||
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
|
||||
end
|
||||
generated_xcode_build_settings.map { |p|
|
||||
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
|
||||
symlink = File.join('.symlinks', 'flutter')
|
||||
File.symlink(File.dirname(p[:path]), symlink)
|
||||
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
|
||||
end
|
||||
}
|
||||
|
||||
# Plugin Pods
|
||||
plugin_pods = parse_KV_file('../.flutter-plugins')
|
||||
plugin_pods.map { |p|
|
||||
symlink = File.join('.symlinks', 'plugins', p[:name])
|
||||
File.symlink(p[:path], symlink)
|
||||
pod p[:name], :path => File.join(symlink, 'ios')
|
||||
}
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['ENABLE_BITCODE'] = 'NO'
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,22 @@
|
||||
PODS:
|
||||
- Flutter (1.0.0)
|
||||
- shared_preferences (0.0.1):
|
||||
- Flutter
|
||||
|
||||
DEPENDENCIES:
|
||||
- Flutter (from `.symlinks/flutter/ios`)
|
||||
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Flutter:
|
||||
:path: ".symlinks/flutter/ios"
|
||||
shared_preferences:
|
||||
:path: ".symlinks/plugins/shared_preferences/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Flutter: 9d0fac939486c9aba2809b7982dfdbb47a7b0296
|
||||
shared_preferences: 5a1d487c427ee18fcd3ea1f2a131569481834b53
|
||||
|
||||
PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09
|
||||
|
||||
COCOAPODS: 1.5.3
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>BuildSystemType</key>
|
||||
<string>Original</string>
|
||||
</dict>
|
||||
</plist>
|
@ -0,0 +1,82 @@
|
||||
// Copyright 2018 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:scoped_model/scoped_model.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 {
|
||||
Preferences() {
|
||||
_loadingFuture = _load();
|
||||
}
|
||||
|
||||
// Keys to use with shared preferences.
|
||||
static const _caloriesKey = 'calories';
|
||||
static const _preferredCategoriesKey = 'preferredCategories';
|
||||
|
||||
// Indicates whether a call to [_load] is in progress;
|
||||
Future<void> _loadingFuture;
|
||||
|
||||
int _desiredCalories = 2000;
|
||||
|
||||
Set<VeggieCategory> _preferredCategories = Set<VeggieCategory>();
|
||||
|
||||
Future<int> get desiredCalories async {
|
||||
await _loadingFuture;
|
||||
return _desiredCalories;
|
||||
}
|
||||
|
||||
Future<Set<VeggieCategory>> get preferredCategories async {
|
||||
await _loadingFuture;
|
||||
return Set.from(_preferredCategories);
|
||||
}
|
||||
|
||||
void addPreferredCategory(VeggieCategory category) {
|
||||
_preferredCategories.add(category);
|
||||
_save();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removePreferredCategory(VeggieCategory category) {
|
||||
_preferredCategories.remove(category);
|
||||
_save();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void setDesiredCalories(int calories) {
|
||||
_desiredCalories = calories;
|
||||
_save();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setInt(_caloriesKey, _desiredCalories);
|
||||
|
||||
// Store preferred categories as a comma-separated string containing their
|
||||
// indices.
|
||||
prefs.setString(_preferredCategoriesKey,
|
||||
_preferredCategories.map((c) => c.index.toString()).join(','));
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_desiredCalories = prefs.getInt(_caloriesKey) ?? 2000;
|
||||
_preferredCategories.clear();
|
||||
final names = prefs.getString(_preferredCategoriesKey) ?? '';
|
||||
|
||||
for (final name in names.split(',')) {
|
||||
final index = int.parse(name) ?? 0;
|
||||
if (VeggieCategory.values[index] != null) {
|
||||
_preferredCategories.add(VeggieCategory.values[index]);
|
||||
}
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue