mirror of https://github.com/flutter/samples.git
Add firebase support to web_dashboard (#421)
* add mock data, app state, model classes * Set up app without ChangeNotifier * refactor * add experiments to experimental/ * Add project-agnostic Firebase authentication code * add sign in button * add stub firebase API * add firestore * refactor code for google_sign_in * update pubspec.lock * switch to mocks for non-firebase version * Add firebase instructions to the README * fix README * sign in silently if the user is already signed in * add json_serializable * update README * ignore 'id' field on types * Implement FirebaseItemApi * Add build_runner instructions to README * remove experiments directory * add EditItemForm * move types.dart into api.dart * move mock and firebase configuration into the constructor * add main_mock entrypoint * add copyright checks to grinder script * fix fix-copyright task * run grind fix-copyright * add run and generate tasks * add run tasks to grind script * add fillWithMockData() fix delete() in mock API * add edit / new form dialogs * Add charts that display entries from Firebase * Add Entries list without editing * refactor home page * format * Add entries page functionality * Show current day in charts * cleanup: pubspec.lock, remove type annotation * Remove _selectedItem from Home page Add ItemsDropdown Use ItemsDropdown in NewEntryDialog / NewEntryForm * rename item-category * don't wait to show snackbar on delete * fix circular progress indicator * Move dialogs into dialogs.dart * run grind fix-copyright * remove unused import * Refactor entry total calculation, add chart_utils library * fix bug in chart_utils.dart * convert CategoryChart to a stateless widget * use a const for number of days in chart * code review updates - rename stream -> subscribe - timeStamp -> timestamp - remove latest() from API - use FutureBuilder and StreamBuilder instead of stateful widget - rename variables in mock_service_test.dart * use a single collection reference in firebase API * remove reference to stream in mock API * Use a new type, _EntriesEvent to improve filtering in mock API * add analysis_options.yaml and fix (most) issues * fix avoid_types_on_closure_parameters lint warnings * use spread operator in dashboard.dart * handle case where selected item in the category dropdown goes away * use StreamBuilder + FutureBuilder on Entries page * rename method * use fake firebase configuration * update pubspec.lock * update README * Change categories_dropdown to FutureBuilder + StreamBuilder * Update minSdkVersion in build.gradle SDK version 16 was failing: "The number of method references in a .dex file cannot exceed 64K." * update README * Use a collection reference in FirebaseEntryApi Already added to FirebaseCategoryApi * Invoke onSelected in CategoriesDropdown when necessary Also, avoid calling onSelected during a build. * fix misnamed var * remove unused import * Use relative imports * Use extension methods for DateTime utilities * remove forms.dart * Make Firebase instructions specific for this sample * add copyright headers * fix grammar * dartfmt * avoid setState() during build phase in CategoryDropdown * add empty test to material_theme_builderpull/450/head
parent
b518c322cc
commit
395ae8c0bb
@ -0,0 +1,31 @@
|
|||||||
|
include: package:pedantic/analysis_options.1.8.0.yaml
|
||||||
|
|
||||||
|
analyzer:
|
||||||
|
strong-mode:
|
||||||
|
implicit-casts: false
|
||||||
|
implicit-dynamic: false
|
||||||
|
|
||||||
|
linter:
|
||||||
|
rules:
|
||||||
|
- avoid_types_on_closure_parameters
|
||||||
|
- avoid_void_async
|
||||||
|
- await_only_futures
|
||||||
|
- camel_case_types
|
||||||
|
- cancel_subscriptions
|
||||||
|
- close_sinks
|
||||||
|
- constant_identifier_names
|
||||||
|
- control_flow_in_finally
|
||||||
|
- directives_ordering
|
||||||
|
- empty_statements
|
||||||
|
- hash_and_equals
|
||||||
|
- implementation_imports
|
||||||
|
- non_constant_identifier_names
|
||||||
|
- package_api_docs
|
||||||
|
- package_names
|
||||||
|
- package_prefixed_library_names
|
||||||
|
- test_types_in_equals
|
||||||
|
- throw_in_finally
|
||||||
|
- unnecessary_brace_in_string_interps
|
||||||
|
- unnecessary_getters_setters
|
||||||
|
- unnecessary_new
|
||||||
|
- unnecessary_statements
|
@ -1 +1,2 @@
|
|||||||
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
# 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
|
||||||
|
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
|
||||||
|
end
|
||||||
|
generated_key_values
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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')
|
||||||
|
end
|
||||||
|
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,410 @@
|
|||||||
|
PODS:
|
||||||
|
- abseil/algorithm (0.20190808):
|
||||||
|
- abseil/algorithm/algorithm (= 0.20190808)
|
||||||
|
- abseil/algorithm/container (= 0.20190808)
|
||||||
|
- abseil/algorithm/algorithm (0.20190808)
|
||||||
|
- abseil/algorithm/container (0.20190808):
|
||||||
|
- abseil/algorithm/algorithm
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/base (0.20190808):
|
||||||
|
- abseil/base/atomic_hook (= 0.20190808)
|
||||||
|
- abseil/base/base (= 0.20190808)
|
||||||
|
- abseil/base/base_internal (= 0.20190808)
|
||||||
|
- abseil/base/bits (= 0.20190808)
|
||||||
|
- abseil/base/config (= 0.20190808)
|
||||||
|
- abseil/base/core_headers (= 0.20190808)
|
||||||
|
- abseil/base/dynamic_annotations (= 0.20190808)
|
||||||
|
- abseil/base/endian (= 0.20190808)
|
||||||
|
- abseil/base/log_severity (= 0.20190808)
|
||||||
|
- abseil/base/malloc_internal (= 0.20190808)
|
||||||
|
- abseil/base/pretty_function (= 0.20190808)
|
||||||
|
- abseil/base/spinlock_wait (= 0.20190808)
|
||||||
|
- abseil/base/throw_delegate (= 0.20190808)
|
||||||
|
- abseil/base/atomic_hook (0.20190808)
|
||||||
|
- abseil/base/base (0.20190808):
|
||||||
|
- abseil/base/atomic_hook
|
||||||
|
- abseil/base/base_internal
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/dynamic_annotations
|
||||||
|
- abseil/base/log_severity
|
||||||
|
- abseil/base/spinlock_wait
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/base/base_internal (0.20190808):
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/base/bits (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/config (0.20190808)
|
||||||
|
- abseil/base/core_headers (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/dynamic_annotations (0.20190808)
|
||||||
|
- abseil/base/endian (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/log_severity (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/malloc_internal (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/dynamic_annotations
|
||||||
|
- abseil/base/spinlock_wait
|
||||||
|
- abseil/base/pretty_function (0.20190808)
|
||||||
|
- abseil/base/spinlock_wait (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/throw_delegate (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/memory (0.20190808):
|
||||||
|
- abseil/memory/memory (= 0.20190808)
|
||||||
|
- abseil/memory/memory (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/meta (0.20190808):
|
||||||
|
- abseil/meta/type_traits (= 0.20190808)
|
||||||
|
- abseil/meta/type_traits (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/numeric/int128 (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/strings/internal (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/endian
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/strings/strings (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/bits
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/endian
|
||||||
|
- abseil/base/throw_delegate
|
||||||
|
- abseil/memory/memory
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/numeric/int128
|
||||||
|
- abseil/strings/internal
|
||||||
|
- abseil/time (0.20190808):
|
||||||
|
- abseil/time/internal (= 0.20190808)
|
||||||
|
- abseil/time/time (= 0.20190808)
|
||||||
|
- abseil/time/internal (0.20190808):
|
||||||
|
- abseil/time/internal/cctz (= 0.20190808)
|
||||||
|
- abseil/time/internal/cctz (0.20190808):
|
||||||
|
- abseil/time/internal/cctz/civil_time (= 0.20190808)
|
||||||
|
- abseil/time/internal/cctz/includes (= 0.20190808)
|
||||||
|
- abseil/time/internal/cctz/time_zone (= 0.20190808)
|
||||||
|
- abseil/time/internal/cctz/civil_time (0.20190808)
|
||||||
|
- abseil/time/internal/cctz/includes (0.20190808)
|
||||||
|
- abseil/time/internal/cctz/time_zone (0.20190808):
|
||||||
|
- abseil/time/internal/cctz/civil_time
|
||||||
|
- abseil/time/time (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/numeric/int128
|
||||||
|
- abseil/strings/strings
|
||||||
|
- abseil/time/internal/cctz/civil_time
|
||||||
|
- abseil/time/internal/cctz/time_zone
|
||||||
|
- abseil/types (0.20190808):
|
||||||
|
- abseil/types/any (= 0.20190808)
|
||||||
|
- abseil/types/bad_any_cast (= 0.20190808)
|
||||||
|
- abseil/types/bad_any_cast_impl (= 0.20190808)
|
||||||
|
- abseil/types/bad_optional_access (= 0.20190808)
|
||||||
|
- abseil/types/bad_variant_access (= 0.20190808)
|
||||||
|
- abseil/types/compare (= 0.20190808)
|
||||||
|
- abseil/types/optional (= 0.20190808)
|
||||||
|
- abseil/types/span (= 0.20190808)
|
||||||
|
- abseil/types/variant (= 0.20190808)
|
||||||
|
- abseil/types/any (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/types/bad_any_cast
|
||||||
|
- abseil/utility/utility
|
||||||
|
- abseil/types/bad_any_cast (0.20190808):
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/types/bad_any_cast_impl
|
||||||
|
- abseil/types/bad_any_cast_impl (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/types/bad_optional_access (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/types/bad_variant_access (0.20190808):
|
||||||
|
- abseil/base/base
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/types/compare (0.20190808):
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/types/optional (0.20190808):
|
||||||
|
- abseil/base/base_internal
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/memory/memory
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/types/bad_optional_access
|
||||||
|
- abseil/utility/utility
|
||||||
|
- abseil/types/span (0.20190808):
|
||||||
|
- abseil/algorithm/algorithm
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/base/throw_delegate
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/types/variant (0.20190808):
|
||||||
|
- abseil/base/base_internal
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/base/core_headers
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- abseil/types/bad_variant_access
|
||||||
|
- abseil/utility/utility
|
||||||
|
- abseil/utility/utility (0.20190808):
|
||||||
|
- abseil/base/base_internal
|
||||||
|
- abseil/base/config
|
||||||
|
- abseil/meta/type_traits
|
||||||
|
- AppAuth (1.3.0):
|
||||||
|
- AppAuth/Core (= 1.3.0)
|
||||||
|
- AppAuth/ExternalUserAgent (= 1.3.0)
|
||||||
|
- AppAuth/Core (1.3.0)
|
||||||
|
- AppAuth/ExternalUserAgent (1.3.0)
|
||||||
|
- BoringSSL-GRPC (0.0.3):
|
||||||
|
- BoringSSL-GRPC/Implementation (= 0.0.3)
|
||||||
|
- BoringSSL-GRPC/Interface (= 0.0.3)
|
||||||
|
- BoringSSL-GRPC/Implementation (0.0.3):
|
||||||
|
- BoringSSL-GRPC/Interface (= 0.0.3)
|
||||||
|
- BoringSSL-GRPC/Interface (0.0.3)
|
||||||
|
- cloud_firestore (0.0.1):
|
||||||
|
- Firebase/Core
|
||||||
|
- Firebase/Firestore (~> 6.0)
|
||||||
|
- Flutter
|
||||||
|
- cloud_firestore_web (0.1.0):
|
||||||
|
- Flutter
|
||||||
|
- Firebase/Auth (6.18.0):
|
||||||
|
- Firebase/CoreOnly
|
||||||
|
- FirebaseAuth (~> 6.4.3)
|
||||||
|
- Firebase/Core (6.18.0):
|
||||||
|
- Firebase/CoreOnly
|
||||||
|
- FirebaseAnalytics (= 6.3.0)
|
||||||
|
- Firebase/CoreOnly (6.18.0):
|
||||||
|
- FirebaseCore (= 6.6.3)
|
||||||
|
- Firebase/Firestore (6.18.0):
|
||||||
|
- Firebase/CoreOnly
|
||||||
|
- FirebaseFirestore (~> 1.11.0)
|
||||||
|
- firebase_auth (0.0.1):
|
||||||
|
- Firebase/Auth (~> 6.3)
|
||||||
|
- Firebase/Core
|
||||||
|
- Flutter
|
||||||
|
- firebase_auth_web (0.1.0):
|
||||||
|
- Flutter
|
||||||
|
- firebase_core (0.0.1):
|
||||||
|
- Firebase/Core
|
||||||
|
- Flutter
|
||||||
|
- firebase_core_web (0.1.0):
|
||||||
|
- Flutter
|
||||||
|
- FirebaseAnalytics (6.3.0):
|
||||||
|
- FirebaseCore (~> 6.6)
|
||||||
|
- FirebaseInstallations (~> 1.1)
|
||||||
|
- GoogleAppMeasurement (= 6.3.0)
|
||||||
|
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
|
||||||
|
- GoogleUtilities/MethodSwizzler (~> 6.0)
|
||||||
|
- GoogleUtilities/Network (~> 6.0)
|
||||||
|
- "GoogleUtilities/NSData+zlib (~> 6.0)"
|
||||||
|
- nanopb (= 0.3.9011)
|
||||||
|
- FirebaseAuth (6.4.3):
|
||||||
|
- FirebaseAuthInterop (~> 1.0)
|
||||||
|
- FirebaseCore (~> 6.6)
|
||||||
|
- GoogleUtilities/AppDelegateSwizzler (~> 6.5)
|
||||||
|
- GoogleUtilities/Environment (~> 6.5)
|
||||||
|
- GTMSessionFetcher/Core (~> 1.1)
|
||||||
|
- FirebaseAuthInterop (1.0.0)
|
||||||
|
- FirebaseCore (6.6.3):
|
||||||
|
- FirebaseCoreDiagnostics (~> 1.2)
|
||||||
|
- FirebaseCoreDiagnosticsInterop (~> 1.2)
|
||||||
|
- GoogleUtilities/Environment (~> 6.5)
|
||||||
|
- GoogleUtilities/Logger (~> 6.5)
|
||||||
|
- FirebaseCoreDiagnostics (1.2.1):
|
||||||
|
- FirebaseCoreDiagnosticsInterop (~> 1.2)
|
||||||
|
- GoogleDataTransportCCTSupport (~> 1.3)
|
||||||
|
- GoogleUtilities/Environment (~> 6.5)
|
||||||
|
- GoogleUtilities/Logger (~> 6.5)
|
||||||
|
- nanopb (~> 0.3.901)
|
||||||
|
- FirebaseCoreDiagnosticsInterop (1.2.0)
|
||||||
|
- FirebaseFirestore (1.11.0):
|
||||||
|
- abseil/algorithm (= 0.20190808)
|
||||||
|
- abseil/base (= 0.20190808)
|
||||||
|
- abseil/memory (= 0.20190808)
|
||||||
|
- abseil/meta (= 0.20190808)
|
||||||
|
- abseil/strings/strings (= 0.20190808)
|
||||||
|
- abseil/time (= 0.20190808)
|
||||||
|
- abseil/types (= 0.20190808)
|
||||||
|
- FirebaseAuthInterop (~> 1.0)
|
||||||
|
- FirebaseCore (~> 6.2)
|
||||||
|
- "gRPC-C++ (= 0.0.9)"
|
||||||
|
- leveldb-library (~> 1.22)
|
||||||
|
- nanopb (~> 0.3.901)
|
||||||
|
- FirebaseInstallations (1.1.0):
|
||||||
|
- FirebaseCore (~> 6.6)
|
||||||
|
- GoogleUtilities/UserDefaults (~> 6.5)
|
||||||
|
- PromisesObjC (~> 1.2)
|
||||||
|
- Flutter (1.0.0)
|
||||||
|
- google_sign_in (0.0.1):
|
||||||
|
- Flutter
|
||||||
|
- GoogleSignIn (~> 5.0)
|
||||||
|
- google_sign_in_web (0.8.1):
|
||||||
|
- Flutter
|
||||||
|
- GoogleAppMeasurement (6.3.0):
|
||||||
|
- GoogleUtilities/AppDelegateSwizzler (~> 6.0)
|
||||||
|
- GoogleUtilities/MethodSwizzler (~> 6.0)
|
||||||
|
- GoogleUtilities/Network (~> 6.0)
|
||||||
|
- "GoogleUtilities/NSData+zlib (~> 6.0)"
|
||||||
|
- nanopb (= 0.3.9011)
|
||||||
|
- GoogleDataTransport (4.0.1)
|
||||||
|
- GoogleDataTransportCCTSupport (1.4.1):
|
||||||
|
- GoogleDataTransport (~> 4.0)
|
||||||
|
- nanopb (~> 0.3.901)
|
||||||
|
- GoogleSignIn (5.0.2):
|
||||||
|
- AppAuth (~> 1.2)
|
||||||
|
- GTMAppAuth (~> 1.0)
|
||||||
|
- GTMSessionFetcher/Core (~> 1.1)
|
||||||
|
- GoogleUtilities/AppDelegateSwizzler (6.5.1):
|
||||||
|
- GoogleUtilities/Environment
|
||||||
|
- GoogleUtilities/Logger
|
||||||
|
- GoogleUtilities/Network
|
||||||
|
- GoogleUtilities/Environment (6.5.1)
|
||||||
|
- GoogleUtilities/Logger (6.5.1):
|
||||||
|
- GoogleUtilities/Environment
|
||||||
|
- GoogleUtilities/MethodSwizzler (6.5.1):
|
||||||
|
- GoogleUtilities/Logger
|
||||||
|
- GoogleUtilities/Network (6.5.1):
|
||||||
|
- GoogleUtilities/Logger
|
||||||
|
- "GoogleUtilities/NSData+zlib"
|
||||||
|
- GoogleUtilities/Reachability
|
||||||
|
- "GoogleUtilities/NSData+zlib (6.5.1)"
|
||||||
|
- GoogleUtilities/Reachability (6.5.1):
|
||||||
|
- GoogleUtilities/Logger
|
||||||
|
- GoogleUtilities/UserDefaults (6.5.1):
|
||||||
|
- GoogleUtilities/Logger
|
||||||
|
- "gRPC-C++ (0.0.9)":
|
||||||
|
- "gRPC-C++/Implementation (= 0.0.9)"
|
||||||
|
- "gRPC-C++/Interface (= 0.0.9)"
|
||||||
|
- "gRPC-C++/Implementation (0.0.9)":
|
||||||
|
- "gRPC-C++/Interface (= 0.0.9)"
|
||||||
|
- gRPC-Core (= 1.21.0)
|
||||||
|
- nanopb (~> 0.3)
|
||||||
|
- "gRPC-C++/Interface (0.0.9)"
|
||||||
|
- gRPC-Core (1.21.0):
|
||||||
|
- gRPC-Core/Implementation (= 1.21.0)
|
||||||
|
- gRPC-Core/Interface (= 1.21.0)
|
||||||
|
- gRPC-Core/Implementation (1.21.0):
|
||||||
|
- BoringSSL-GRPC (= 0.0.3)
|
||||||
|
- gRPC-Core/Interface (= 1.21.0)
|
||||||
|
- nanopb (~> 0.3)
|
||||||
|
- gRPC-Core/Interface (1.21.0)
|
||||||
|
- GTMAppAuth (1.0.0):
|
||||||
|
- AppAuth/Core (~> 1.0)
|
||||||
|
- GTMSessionFetcher (~> 1.1)
|
||||||
|
- GTMSessionFetcher (1.3.1):
|
||||||
|
- GTMSessionFetcher/Full (= 1.3.1)
|
||||||
|
- GTMSessionFetcher/Core (1.3.1)
|
||||||
|
- GTMSessionFetcher/Full (1.3.1):
|
||||||
|
- GTMSessionFetcher/Core (= 1.3.1)
|
||||||
|
- leveldb-library (1.22)
|
||||||
|
- nanopb (0.3.9011):
|
||||||
|
- nanopb/decode (= 0.3.9011)
|
||||||
|
- nanopb/encode (= 0.3.9011)
|
||||||
|
- nanopb/decode (0.3.9011)
|
||||||
|
- nanopb/encode (0.3.9011)
|
||||||
|
- PromisesObjC (1.2.8)
|
||||||
|
|
||||||
|
DEPENDENCIES:
|
||||||
|
- cloud_firestore (from `.symlinks/plugins/cloud_firestore/ios`)
|
||||||
|
- cloud_firestore_web (from `.symlinks/plugins/cloud_firestore_web/ios`)
|
||||||
|
- firebase_auth (from `.symlinks/plugins/firebase_auth/ios`)
|
||||||
|
- firebase_auth_web (from `.symlinks/plugins/firebase_auth_web/ios`)
|
||||||
|
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
|
||||||
|
- firebase_core_web (from `.symlinks/plugins/firebase_core_web/ios`)
|
||||||
|
- Flutter (from `Flutter`)
|
||||||
|
- google_sign_in (from `.symlinks/plugins/google_sign_in/ios`)
|
||||||
|
- google_sign_in_web (from `.symlinks/plugins/google_sign_in_web/ios`)
|
||||||
|
|
||||||
|
SPEC REPOS:
|
||||||
|
trunk:
|
||||||
|
- abseil
|
||||||
|
- AppAuth
|
||||||
|
- BoringSSL-GRPC
|
||||||
|
- Firebase
|
||||||
|
- FirebaseAnalytics
|
||||||
|
- FirebaseAuth
|
||||||
|
- FirebaseAuthInterop
|
||||||
|
- FirebaseCore
|
||||||
|
- FirebaseCoreDiagnostics
|
||||||
|
- FirebaseCoreDiagnosticsInterop
|
||||||
|
- FirebaseFirestore
|
||||||
|
- FirebaseInstallations
|
||||||
|
- GoogleAppMeasurement
|
||||||
|
- GoogleDataTransport
|
||||||
|
- GoogleDataTransportCCTSupport
|
||||||
|
- GoogleSignIn
|
||||||
|
- GoogleUtilities
|
||||||
|
- "gRPC-C++"
|
||||||
|
- gRPC-Core
|
||||||
|
- GTMAppAuth
|
||||||
|
- GTMSessionFetcher
|
||||||
|
- leveldb-library
|
||||||
|
- nanopb
|
||||||
|
- PromisesObjC
|
||||||
|
|
||||||
|
EXTERNAL SOURCES:
|
||||||
|
cloud_firestore:
|
||||||
|
:path: ".symlinks/plugins/cloud_firestore/ios"
|
||||||
|
cloud_firestore_web:
|
||||||
|
:path: ".symlinks/plugins/cloud_firestore_web/ios"
|
||||||
|
firebase_auth:
|
||||||
|
:path: ".symlinks/plugins/firebase_auth/ios"
|
||||||
|
firebase_auth_web:
|
||||||
|
:path: ".symlinks/plugins/firebase_auth_web/ios"
|
||||||
|
firebase_core:
|
||||||
|
:path: ".symlinks/plugins/firebase_core/ios"
|
||||||
|
firebase_core_web:
|
||||||
|
:path: ".symlinks/plugins/firebase_core_web/ios"
|
||||||
|
Flutter:
|
||||||
|
:path: Flutter
|
||||||
|
google_sign_in:
|
||||||
|
:path: ".symlinks/plugins/google_sign_in/ios"
|
||||||
|
google_sign_in_web:
|
||||||
|
:path: ".symlinks/plugins/google_sign_in_web/ios"
|
||||||
|
|
||||||
|
SPEC CHECKSUMS:
|
||||||
|
abseil: 18063d773f5366ff8736a050fe035a28f635fd27
|
||||||
|
AppAuth: 73574f3013a1e65b9601a3ddc8b3158cce68c09d
|
||||||
|
BoringSSL-GRPC: db8764df3204ccea016e1c8dd15d9a9ad63ff318
|
||||||
|
cloud_firestore: 31454d48df21f3e1a900015e36143c0d46a304b7
|
||||||
|
cloud_firestore_web: 9ec3dc7f5f98de5129339802d491c1204462bfec
|
||||||
|
Firebase: 0490eca762a72e4f1582319539153897f1508dee
|
||||||
|
firebase_auth: 4ee3a54d3f09434c508c284a62f895a741a30637
|
||||||
|
firebase_auth_web: 0955c07bcc06e84af76b9d4e32e6f31518f2d7de
|
||||||
|
firebase_core: 0d8be0e0d14c4902953aeb5ac5d7316d1fe4b978
|
||||||
|
firebase_core_web: d501d8b946b60c8af265428ce483b0fff5ad52d1
|
||||||
|
FirebaseAnalytics: 058d71e714a1a6804d9e0f25e3bb18e377a51579
|
||||||
|
FirebaseAuth: 5ce2b03a3d7fe56b7a6e4c5ec7ff1522890b1d6f
|
||||||
|
FirebaseAuthInterop: 0ffa57668be100582bb7643d4fcb7615496c41fc
|
||||||
|
FirebaseCore: 78276943ad85e616dfa54dafa6c89512987d9d60
|
||||||
|
FirebaseCoreDiagnostics: 2109d10c35e8289b1ee6cabf44d9ffb055620194
|
||||||
|
FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850
|
||||||
|
FirebaseFirestore: a23d596ae3a8c13d3b8353b565d2adfb690f9032
|
||||||
|
FirebaseInstallations: 575cd32f2aec0feeb0e44f5d0110a09e5e60b47b
|
||||||
|
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
|
||||||
|
google_sign_in: f32920a589fdf4ab2918ec6dc5e5b0d5b8040ff5
|
||||||
|
google_sign_in_web: 52deb24929ac0992baff65c57956031c44ed44c3
|
||||||
|
GoogleAppMeasurement: 39ecba10918b21c83877d392246157f65db351cf
|
||||||
|
GoogleDataTransport: 653963cf5be60fb59cf051e070f0836fdc305f81
|
||||||
|
GoogleDataTransportCCTSupport: 84e4d4bbab642f2e9d83ee65d78aca2b5527d314
|
||||||
|
GoogleSignIn: 7137d297ddc022a7e0aa4619c86d72c909fa7213
|
||||||
|
GoogleUtilities: 06eb53bb579efe7099152735900dd04bf09e7275
|
||||||
|
"gRPC-C++": 9dfe7b44821e7b3e44aacad2af29d2c21f7cde83
|
||||||
|
gRPC-Core: c9aef9a261a1247e881b18059b84d597293c9947
|
||||||
|
GTMAppAuth: 4deac854479704f348309e7b66189e604cf5e01e
|
||||||
|
GTMSessionFetcher: cea130bbfe5a7edc8d06d3f0d17288c32ffe9925
|
||||||
|
leveldb-library: 55d93ee664b4007aac644a782d11da33fba316f7
|
||||||
|
nanopb: 18003b5e52dab79db540fe93fe9579f399bd1ccd
|
||||||
|
PromisesObjC: c119f3cd559f50b7ae681fa59dc1acd19173b7e6
|
||||||
|
|
||||||
|
PODFILE CHECKSUM: c34e2287a9ccaa606aeceab922830efb9a6ff69a
|
||||||
|
|
||||||
|
COCOAPODS: 1.9.1
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'src/app.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
runApp(DashboardApp.mock());
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'api.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// JsonSerializableGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
Category _$CategoryFromJson(Map<String, dynamic> json) {
|
||||||
|
return Category(
|
||||||
|
json['name'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$CategoryToJson(Category instance) => <String, dynamic>{
|
||||||
|
'name': instance.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
Entry _$EntryFromJson(Map<String, dynamic> json) {
|
||||||
|
return Entry(
|
||||||
|
json['value'] as int,
|
||||||
|
Entry._timestampToDateTime(json['time'] as Timestamp),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> _$EntryToJson(Entry instance) => <String, dynamic>{
|
||||||
|
'value': instance.value,
|
||||||
|
'time': Entry._dateTimeToTimestamp(instance.time),
|
||||||
|
};
|
@ -1,3 +1,151 @@
|
|||||||
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
|
|
||||||
|
import 'api.dart';
|
||||||
|
|
||||||
|
class FirebaseDashboardApi implements DashboardApi {
|
||||||
|
@override
|
||||||
|
final EntryApi entries;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final CategoryApi categories;
|
||||||
|
|
||||||
|
FirebaseDashboardApi(Firestore firestore, String userId)
|
||||||
|
: entries = FirebaseEntryApi(firestore, userId),
|
||||||
|
categories = FirebaseCategoryApi(firestore, userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
class FirebaseEntryApi implements EntryApi {
|
||||||
|
final Firestore firestore;
|
||||||
|
final String userId;
|
||||||
|
final CollectionReference _categoriesRef;
|
||||||
|
|
||||||
|
FirebaseEntryApi(this.firestore, this.userId)
|
||||||
|
: _categoriesRef = firestore.collection('users/$userId/categories');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<List<Entry>> subscribe(String categoryId) {
|
||||||
|
var snapshots = _categoriesRef
|
||||||
|
.document('$categoryId')
|
||||||
|
.collection('entries')
|
||||||
|
.snapshots();
|
||||||
|
var result = snapshots.map((querySnapshot) {
|
||||||
|
return querySnapshot.documents.map((snapshot) {
|
||||||
|
return Entry.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}).toList();
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Entry> delete(String categoryId, String id) async {
|
||||||
|
var document = _categoriesRef.document('$categoryId/entries/$id');
|
||||||
|
var entry = await get(categoryId, document.documentID);
|
||||||
|
|
||||||
|
await document.delete();
|
||||||
|
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Entry> insert(String categoryId, Entry entry) async {
|
||||||
|
var document = await _categoriesRef
|
||||||
|
.document('$categoryId')
|
||||||
|
.collection('entries')
|
||||||
|
.add(entry.toJson());
|
||||||
|
return await get(categoryId, document.documentID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Entry>> list(String categoryId) async {
|
||||||
|
var entriesRef =
|
||||||
|
_categoriesRef.document('$categoryId').collection('entries');
|
||||||
|
var querySnapshot = await entriesRef.getDocuments();
|
||||||
|
var entries = querySnapshot.documents
|
||||||
|
.map((doc) => Entry.fromJson(doc.data)..id = doc.documentID)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Entry> update(String categoryId, String id, Entry entry) async {
|
||||||
|
var document = _categoriesRef.document('$categoryId/entries/$id');
|
||||||
|
await document.setData(entry.toJson());
|
||||||
|
var snapshot = await document.get();
|
||||||
|
return Entry.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Entry> get(String categoryId, String id) async {
|
||||||
|
var document = _categoriesRef.document('$categoryId/entries/$id');
|
||||||
|
var snapshot = await document.get();
|
||||||
|
return Entry.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class FirebaseCategoryApi implements CategoryApi {
|
||||||
|
final Firestore firestore;
|
||||||
|
final String userId;
|
||||||
|
final CollectionReference _categoriesRef;
|
||||||
|
|
||||||
|
FirebaseCategoryApi(this.firestore, this.userId)
|
||||||
|
: _categoriesRef = firestore.collection('users/$userId/categories');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Stream<List<Category>> subscribe() {
|
||||||
|
var snapshots = _categoriesRef.snapshots();
|
||||||
|
var result = snapshots.map((querySnapshot) {
|
||||||
|
return querySnapshot.documents.map((snapshot) {
|
||||||
|
return Category.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}).toList();
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Category> delete(String id) async {
|
||||||
|
var document = _categoriesRef.document('$id');
|
||||||
|
var categories = await get(document.documentID);
|
||||||
|
|
||||||
|
await document.delete();
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Category> get(String id) async {
|
||||||
|
var document = _categoriesRef.document('$id');
|
||||||
|
var snapshot = await document.get();
|
||||||
|
return Category.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Category> insert(Category category) async {
|
||||||
|
var document = await _categoriesRef.add(category.toJson());
|
||||||
|
return await get(document.documentID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Category>> list() async {
|
||||||
|
var querySnapshot = await _categoriesRef.getDocuments();
|
||||||
|
var categories = querySnapshot.documents
|
||||||
|
.map((doc) => Category.fromJson(doc.data)..id = doc.documentID)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<Category> update(Category category, String id) async {
|
||||||
|
var document = _categoriesRef.document('$id');
|
||||||
|
await document.setData(category.toJson());
|
||||||
|
var snapshot = await document.get();
|
||||||
|
return Category.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
abstract class Auth {
|
||||||
|
Future<User> signIn();
|
||||||
|
Future signOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class User {
|
||||||
|
String get uid;
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
|
import 'package:firebase_auth/firebase_auth.dart' hide FirebaseUser;
|
||||||
|
|
||||||
|
import 'auth.dart';
|
||||||
|
|
||||||
|
class FirebaseAuthService implements Auth {
|
||||||
|
final GoogleSignIn _googleSignIn = GoogleSignIn();
|
||||||
|
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||||
|
|
||||||
|
Future<User> signIn() async {
|
||||||
|
GoogleSignInAccount googleUser;
|
||||||
|
if (await _googleSignIn.isSignedIn()) {
|
||||||
|
googleUser = await _googleSignIn.signInSilently();
|
||||||
|
} else {
|
||||||
|
googleUser = await _googleSignIn.signIn();
|
||||||
|
}
|
||||||
|
|
||||||
|
var googleAuth = await googleUser.authentication;
|
||||||
|
|
||||||
|
var credential = GoogleAuthProvider.getCredential(
|
||||||
|
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
|
||||||
|
|
||||||
|
var authResult = await _auth.signInWithCredential(credential);
|
||||||
|
|
||||||
|
return _FirebaseUser(authResult.user.uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> signOut() async {
|
||||||
|
await _auth.signOut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FirebaseUser implements User {
|
||||||
|
final String uid;
|
||||||
|
|
||||||
|
_FirebaseUser(this.uid);
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'auth.dart';
|
||||||
|
|
||||||
|
class MockAuthService implements Auth {
|
||||||
|
@override
|
||||||
|
Future<User> signIn() async {
|
||||||
|
return MockUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future signOut() async {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MockUser implements User {
|
||||||
|
String get uid => "123";
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../api/api.dart';
|
||||||
|
import '../app.dart';
|
||||||
|
import '../widgets/category_chart.dart';
|
||||||
|
|
||||||
|
class DashboardPage extends StatelessWidget {
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var appState = Provider.of<AppState>(context);
|
||||||
|
return FutureBuilder<List<Category>>(
|
||||||
|
future: appState.api.categories.list(),
|
||||||
|
builder: (context, futureSnapshot) {
|
||||||
|
if (!futureSnapshot.hasData) {
|
||||||
|
return Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return StreamBuilder<List<Category>>(
|
||||||
|
initialData: futureSnapshot.data,
|
||||||
|
stream: appState.api.categories.subscribe(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.data == null) {
|
||||||
|
return Center(
|
||||||
|
child: CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Dashboard(snapshot.data);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dashboard extends StatelessWidget {
|
||||||
|
final List<Category> categories;
|
||||||
|
|
||||||
|
Dashboard(this.categories);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var api = Provider.of<AppState>(context).api;
|
||||||
|
return Scrollbar(
|
||||||
|
child: GridView(
|
||||||
|
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
|
childAspectRatio: 2,
|
||||||
|
maxCrossAxisExtent: 500,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
...categories.map(
|
||||||
|
(category) => Card(
|
||||||
|
child: CategoryChart(
|
||||||
|
category: category,
|
||||||
|
api: api,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import '../api/api.dart';
|
||||||
|
import '../app.dart';
|
||||||
|
import '../widgets/categories_dropdown.dart';
|
||||||
|
import '../widgets/dialogs.dart';
|
||||||
|
|
||||||
|
class EntriesPage extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_EntriesPageState createState() => _EntriesPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EntriesPageState extends State<EntriesPage> {
|
||||||
|
Category _selected;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var appState = Provider.of<AppState>(context);
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
CategoryDropdown(
|
||||||
|
api: appState.api.categories,
|
||||||
|
onSelected: (category) => setState(() => _selected = category)),
|
||||||
|
Expanded(
|
||||||
|
child: _selected == null
|
||||||
|
? Center(child: CircularProgressIndicator())
|
||||||
|
: EntriesList(
|
||||||
|
category: _selected,
|
||||||
|
api: appState.api.entries,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntriesList extends StatefulWidget {
|
||||||
|
final Category category;
|
||||||
|
final EntryApi api;
|
||||||
|
|
||||||
|
EntriesList({
|
||||||
|
@required this.category,
|
||||||
|
@required this.api,
|
||||||
|
}) : super(key: ValueKey(category.id));
|
||||||
|
|
||||||
|
@override
|
||||||
|
_EntriesListState createState() => _EntriesListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EntriesListState extends State<EntriesList> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (widget.category == null) {
|
||||||
|
return _buildLoadingIndicator();
|
||||||
|
}
|
||||||
|
|
||||||
|
return FutureBuilder<List<Entry>>(
|
||||||
|
future: widget.api.list(widget.category.id),
|
||||||
|
builder: (context, futureSnapshot) {
|
||||||
|
if (!futureSnapshot.hasData) {
|
||||||
|
return _buildLoadingIndicator();
|
||||||
|
}
|
||||||
|
return StreamBuilder<List<Entry>>(
|
||||||
|
initialData: futureSnapshot.data,
|
||||||
|
stream: widget.api.subscribe(widget.category.id),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return _buildLoadingIndicator();
|
||||||
|
}
|
||||||
|
return ListView.builder(
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return EntryTile(
|
||||||
|
category: widget.category,
|
||||||
|
entry: snapshot.data[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
itemCount: snapshot.data.length,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildLoadingIndicator() {
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EntryTile extends StatelessWidget {
|
||||||
|
final Category category;
|
||||||
|
final Entry entry;
|
||||||
|
|
||||||
|
EntryTile({
|
||||||
|
this.category,
|
||||||
|
this.entry,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ListTile(
|
||||||
|
title: Text(entry.value.toString()),
|
||||||
|
subtitle: Text(intl.DateFormat('MM/dd/yy h:mm a').format(entry.time)),
|
||||||
|
trailing: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
FlatButton(
|
||||||
|
child: Text('Edit'),
|
||||||
|
onPressed: () {
|
||||||
|
showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return EditEntryDialog(category: category, entry: entry);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
FlatButton(
|
||||||
|
child: Text('Delete'),
|
||||||
|
onPressed: () async {
|
||||||
|
var shouldDelete = await showDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => AlertDialog(
|
||||||
|
title: Text('Delete entry?'),
|
||||||
|
actions: [
|
||||||
|
FlatButton(
|
||||||
|
child: Text('Cancel'),
|
||||||
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
|
),
|
||||||
|
FlatButton(
|
||||||
|
child: Text('Delete'),
|
||||||
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (shouldDelete) {
|
||||||
|
await Provider.of<AppState>(context, listen: false)
|
||||||
|
.api
|
||||||
|
.entries
|
||||||
|
.delete(category.id, entry.id);
|
||||||
|
|
||||||
|
Scaffold.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('Entry deleted'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:web_dashboard/src/api/api.dart';
|
|
||||||
|
|
||||||
class ItemDetailsPage extends StatelessWidget {
|
|
||||||
final Item item;
|
|
||||||
|
|
||||||
ItemDetailsPage(this.item);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(),
|
|
||||||
body: Center(
|
|
||||||
child: Text('${item.name}'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../auth/auth.dart';
|
||||||
|
|
||||||
|
class SignInPage extends StatefulWidget {
|
||||||
|
final Auth auth;
|
||||||
|
final ValueChanged<User> onSuccess;
|
||||||
|
|
||||||
|
SignInPage({
|
||||||
|
@required this.auth,
|
||||||
|
@required this.onSuccess,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_SignInPageState createState() => _SignInPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SignInPageState extends State<SignInPage> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text('Sign In'),
|
||||||
|
onPressed: () async {
|
||||||
|
var user = await widget.auth.signIn();
|
||||||
|
if (user != null) {
|
||||||
|
widget.onSuccess(user);
|
||||||
|
} else {
|
||||||
|
throw ('Unable to sign in');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import '../api/api.dart';
|
||||||
|
import 'day_helpers.dart';
|
||||||
|
|
||||||
|
/// The total value of one or more [Entry]s on a given day.
|
||||||
|
class EntryTotal {
|
||||||
|
final DateTime day;
|
||||||
|
int value;
|
||||||
|
|
||||||
|
EntryTotal(this.day, this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a list of [EntryTotal] objects. Each [EntryTotal] is the sum of
|
||||||
|
/// the values of all the entries on a given day.
|
||||||
|
List<EntryTotal> entryTotalsByDay(List<Entry> entries, int daysAgo,
|
||||||
|
{DateTime today}) {
|
||||||
|
today ??= DateTime.now();
|
||||||
|
return _entryTotalsByDay(entries, daysAgo, today).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Iterable<EntryTotal> _entryTotalsByDay(
|
||||||
|
List<Entry> entries, int daysAgo, DateTime today) sync* {
|
||||||
|
var start = today.subtract(Duration(days: daysAgo));
|
||||||
|
var entriesByDay = _entriesInRange(start, today, entries);
|
||||||
|
|
||||||
|
for (var i = 0; i < entriesByDay.length; i++) {
|
||||||
|
var list = entriesByDay[i];
|
||||||
|
var entryTotal = EntryTotal(start.add(Duration(days: i)), 0);
|
||||||
|
|
||||||
|
for (var entry in list) {
|
||||||
|
entryTotal.value += entry.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
yield entryTotal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Groups entries by day between [start] and [end]. The result is a list of
|
||||||
|
/// lists. The outer list represents the number of days since [start], and the
|
||||||
|
/// inner list is the group of entries on that day.
|
||||||
|
List<List<Entry>> _entriesInRange(
|
||||||
|
DateTime start, DateTime end, List<Entry> entries) =>
|
||||||
|
_entriesInRangeImpl(start, end, entries).toList();
|
||||||
|
|
||||||
|
Iterable<List<Entry>> _entriesInRangeImpl(
|
||||||
|
DateTime start, DateTime end, List<Entry> entries) sync* {
|
||||||
|
start = start.atMidnight;
|
||||||
|
end = end.atMidnight;
|
||||||
|
var d = start;
|
||||||
|
|
||||||
|
while (d.compareTo(end) <= 0) {
|
||||||
|
var es = <Entry>[];
|
||||||
|
for (var entry in entries) {
|
||||||
|
if (d.isSameDay(entry.time.atMidnight)) {
|
||||||
|
es.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
yield es;
|
||||||
|
d = d.add(Duration(days: 1));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
extension DayUtils on DateTime {
|
||||||
|
/// The UTC date portion of a datetime, without the minutes, seconds, etc.
|
||||||
|
DateTime get atMidnight {
|
||||||
|
return DateTime.utc(year, month, day);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks that the two [DateTime]s share the same date.
|
||||||
|
bool isSameDay(DateTime d2) {
|
||||||
|
return this.year == d2.year && this.month == d2.month && this.day == d2.day;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. 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:flutter/material.dart';
|
||||||
|
import '../api/api.dart';
|
||||||
|
|
||||||
|
/// Subscribes to the latest list of categories and allows the user to select
|
||||||
|
/// one.
|
||||||
|
class CategoryDropdown extends StatefulWidget {
|
||||||
|
final CategoryApi api;
|
||||||
|
final ValueChanged<Category> onSelected;
|
||||||
|
|
||||||
|
CategoryDropdown({
|
||||||
|
@required this.api,
|
||||||
|
@required this.onSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_CategoryDropdownState createState() => _CategoryDropdownState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CategoryDropdownState extends State<CategoryDropdown> {
|
||||||
|
Category _selected;
|
||||||
|
Future<List<Category>> _future;
|
||||||
|
Stream<List<Category>> _stream;
|
||||||
|
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
// This widget needs to wait for the list of Categories, select the first
|
||||||
|
// Category, and emit an `onSelected` event.
|
||||||
|
//
|
||||||
|
// This could be done inside the FutureBuilder's `builder` callback,
|
||||||
|
// but calling setState() during the build is an error. (Calling the
|
||||||
|
// onSelected callback will also cause the parent widget to call
|
||||||
|
// setState()).
|
||||||
|
//
|
||||||
|
// Instead, we'll create a new Future that sets the selected Category and
|
||||||
|
// calls `onSelected` if necessary. Then, we'll pass *that* future to
|
||||||
|
// FutureBuilder. Now the selected category is set and events are emitted
|
||||||
|
// *before* the build is triggered by the FutureBuilder.
|
||||||
|
_future = widget.api.list().then((categories) {
|
||||||
|
if (categories.isEmpty) {
|
||||||
|
return categories;
|
||||||
|
}
|
||||||
|
|
||||||
|
_setSelected(categories.first);
|
||||||
|
return categories;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Same here, we'll create a new stream that handles any potential
|
||||||
|
// setState() operations before we trigger our StreamBuilder.
|
||||||
|
_stream = widget.api.subscribe().map((categories) {
|
||||||
|
if (!categories.contains(_selected) && categories.isNotEmpty) {
|
||||||
|
_setSelected(categories.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
return categories;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder<List<Category>>(
|
||||||
|
future: _future,
|
||||||
|
builder: (context, futureSnapshot) {
|
||||||
|
// Show an empty dropdown while the data is loading.
|
||||||
|
if (!futureSnapshot.hasData) {
|
||||||
|
return DropdownButton<Category>(items: [], onChanged: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return StreamBuilder<List<Category>>(
|
||||||
|
initialData: futureSnapshot.hasData ? futureSnapshot.data : [],
|
||||||
|
stream: _stream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
var data = snapshot.hasData ? snapshot.data : <Category>[];
|
||||||
|
return DropdownButton<Category>(
|
||||||
|
value: _selected,
|
||||||
|
items: data.map(_buildDropdownItem).toList(),
|
||||||
|
onChanged: (category) {
|
||||||
|
_setSelected(category);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setSelected(Category category) {
|
||||||
|
if (_selected == category) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_selected = category;
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.onSelected(_selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
DropdownMenuItem<Category> _buildDropdownItem(Category category) {
|
||||||
|
return DropdownMenuItem<Category>(
|
||||||
|
child: Text(category.name), value: category);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:charts_flutter/flutter.dart' as charts;
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import '../api/api.dart';
|
||||||
|
import '../utils/chart_utils.dart' as utils;
|
||||||
|
import 'dialogs.dart';
|
||||||
|
|
||||||
|
// The number of days to show in the chart
|
||||||
|
const _daysBefore = 10;
|
||||||
|
|
||||||
|
class CategoryChart extends StatelessWidget {
|
||||||
|
final Category category;
|
||||||
|
final DashboardApi api;
|
||||||
|
|
||||||
|
CategoryChart({
|
||||||
|
@required this.category,
|
||||||
|
@required this.api,
|
||||||
|
});
|
||||||
|
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(category.name),
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(Icons.settings),
|
||||||
|
onPressed: () {
|
||||||
|
showDialog<EditCategoryDialog>(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return EditCategoryDialog(category: category);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
// Load the initial snapshot using a FutureBuilder, and subscribe to
|
||||||
|
// additional updates with a StreamBuilder.
|
||||||
|
child: FutureBuilder<List<Entry>>(
|
||||||
|
future: api.entries.list(category.id),
|
||||||
|
builder: (context, futureSnapshot) {
|
||||||
|
if (!futureSnapshot.hasData) {
|
||||||
|
return _buildLoadingIndicator();
|
||||||
|
}
|
||||||
|
return StreamBuilder<List<Entry>>(
|
||||||
|
initialData: futureSnapshot.data,
|
||||||
|
stream: api.entries.subscribe(category.id),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (!snapshot.hasData) {
|
||||||
|
return _buildLoadingIndicator();
|
||||||
|
}
|
||||||
|
return _BarChart(entries: snapshot.data);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildLoadingIndicator() {
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BarChart extends StatelessWidget {
|
||||||
|
final List<Entry> entries;
|
||||||
|
|
||||||
|
_BarChart({this.entries});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return charts.BarChart(
|
||||||
|
[_seriesData()],
|
||||||
|
animate: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
charts.Series<utils.EntryTotal, String> _seriesData() {
|
||||||
|
return charts.Series<utils.EntryTotal, String>(
|
||||||
|
id: 'Entries',
|
||||||
|
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||||
|
domainFn: (entryTotal, _) {
|
||||||
|
if (entryTotal == null) return null;
|
||||||
|
|
||||||
|
var format = intl.DateFormat.Md();
|
||||||
|
return format.format(entryTotal.day);
|
||||||
|
},
|
||||||
|
measureFn: (total, _) {
|
||||||
|
if (total == null) return null;
|
||||||
|
|
||||||
|
return total.value;
|
||||||
|
},
|
||||||
|
data: utils.entryTotalsByDay(entries, _daysBefore),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:web_dashboard/src/api/api.dart';
|
||||||
|
import 'package:web_dashboard/src/app.dart';
|
||||||
|
|
||||||
|
class NewCategoryForm extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_NewCategoryFormState createState() => _NewCategoryFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewCategoryFormState extends State<NewCategoryForm> {
|
||||||
|
Category _category = Category('');
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var api = Provider.of<AppState>(context).api;
|
||||||
|
return EditCategoryForm(
|
||||||
|
category: _category,
|
||||||
|
onDone: (shouldInsert) {
|
||||||
|
if (shouldInsert) {
|
||||||
|
api.categories.insert(_category);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditCategoryForm extends StatefulWidget {
|
||||||
|
final Category category;
|
||||||
|
final ValueChanged<bool> onDone;
|
||||||
|
|
||||||
|
EditCategoryForm({
|
||||||
|
@required this.category,
|
||||||
|
@required this.onDone,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_EditCategoryFormState createState() => _EditCategoryFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditCategoryFormState extends State<EditCategoryForm> {
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: TextFormField(
|
||||||
|
initialValue: widget.category.name,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: 'Name',
|
||||||
|
),
|
||||||
|
onChanged: (newValue) {
|
||||||
|
widget.category.name = newValue;
|
||||||
|
},
|
||||||
|
validator: (value) {
|
||||||
|
if (value.isEmpty) {
|
||||||
|
return 'Please enter a name';
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text('Cancel'),
|
||||||
|
onPressed: () {
|
||||||
|
widget.onDone(false);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
if (_formKey.currentState.validate()) {
|
||||||
|
widget.onDone(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,98 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:web_dashboard/src/api/api.dart';
|
||||||
|
import 'package:web_dashboard/src/widgets/category_forms.dart';
|
||||||
|
|
||||||
|
import '../app.dart';
|
||||||
|
import 'edit_entry.dart';
|
||||||
|
|
||||||
|
class NewCategoryDialog extends StatelessWidget {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text('New Category'),
|
||||||
|
children: <Widget>[
|
||||||
|
NewCategoryForm(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditCategoryDialog extends StatelessWidget {
|
||||||
|
final Category category;
|
||||||
|
|
||||||
|
EditCategoryDialog({
|
||||||
|
@required this.category,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var api = Provider.of<AppState>(context).api;
|
||||||
|
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text('Edit Category'),
|
||||||
|
children: [
|
||||||
|
EditCategoryForm(
|
||||||
|
category: category,
|
||||||
|
onDone: (shouldUpdate) {
|
||||||
|
if (shouldUpdate) {
|
||||||
|
api.categories.update(category, category.id);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewEntryDialog extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_NewEntryDialogState createState() => _NewEntryDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewEntryDialogState extends State<NewEntryDialog> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text('New Entry'),
|
||||||
|
children: [
|
||||||
|
NewEntryForm(),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditEntryDialog extends StatelessWidget {
|
||||||
|
final Category category;
|
||||||
|
final Entry entry;
|
||||||
|
|
||||||
|
EditEntryDialog({
|
||||||
|
this.category,
|
||||||
|
this.entry,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var api = Provider.of<AppState>(context).api;
|
||||||
|
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text('Edit Entry'),
|
||||||
|
children: [
|
||||||
|
EditEntryForm(
|
||||||
|
entry: entry,
|
||||||
|
onDone: (shouldUpdate) {
|
||||||
|
if (shouldUpdate) {
|
||||||
|
api.entries.update(category.id, entry.id, entry);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,154 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:web_dashboard/src/api/api.dart';
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import '../app.dart';
|
||||||
|
import 'categories_dropdown.dart';
|
||||||
|
|
||||||
|
class NewEntryForm extends StatefulWidget {
|
||||||
|
@override
|
||||||
|
_NewEntryFormState createState() => _NewEntryFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NewEntryFormState extends State<NewEntryForm> {
|
||||||
|
Category _selected;
|
||||||
|
Entry _entry = Entry(0, DateTime.now());
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var api = Provider.of<AppState>(context).api;
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: CategoryDropdown(
|
||||||
|
api: api.categories,
|
||||||
|
onSelected: (category) {
|
||||||
|
setState(() {
|
||||||
|
_selected = category;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
EditEntryForm(
|
||||||
|
entry: _entry,
|
||||||
|
onDone: (shouldInsert) {
|
||||||
|
if (shouldInsert) {
|
||||||
|
api.entries.insert(_selected.id, _entry);
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class EditEntryForm extends StatefulWidget {
|
||||||
|
final Entry entry;
|
||||||
|
final ValueChanged<bool> onDone;
|
||||||
|
|
||||||
|
EditEntryForm({
|
||||||
|
@required this.entry,
|
||||||
|
@required this.onDone,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_EditEntryFormState createState() => _EditEntryFormState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _EditEntryFormState extends State<EditEntryForm> {
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Form(
|
||||||
|
key: _formKey,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: TextFormField(
|
||||||
|
initialValue: widget.entry.value.toString(),
|
||||||
|
decoration: InputDecoration(labelText: 'Value'),
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
validator: (value) {
|
||||||
|
try {
|
||||||
|
int.parse(value);
|
||||||
|
} catch (e) {
|
||||||
|
return "Please enter a whole number";
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
onChanged: (newValue) {
|
||||||
|
try {
|
||||||
|
widget.entry.value = int.parse(newValue);
|
||||||
|
} on FormatException {
|
||||||
|
print('Entry cannot contain "$newValue". Expected a number');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.all(8),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Text(intl.DateFormat('MM/dd/yyyy').format(widget.entry.time)),
|
||||||
|
RaisedButton(
|
||||||
|
child: Text('Edit'),
|
||||||
|
onPressed: () async {
|
||||||
|
var result = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
initialDate: widget.entry.time,
|
||||||
|
firstDate: DateTime.now().subtract(Duration(days: 365)),
|
||||||
|
lastDate: DateTime.now());
|
||||||
|
if (result == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
widget.entry.time = result;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text('Cancel'),
|
||||||
|
onPressed: () {
|
||||||
|
widget.onDone(false);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||||
|
child: RaisedButton(
|
||||||
|
child: Text('OK'),
|
||||||
|
onPressed: () {
|
||||||
|
if (_formKey.currentState.validate()) {
|
||||||
|
widget.onDone(true);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,17 +1,26 @@
|
|||||||
name: web_dashboard
|
name: web_dashboard
|
||||||
description: A desktop-friendly dashboard app
|
description: A dashboard app sample
|
||||||
version: 1.0.0+1
|
version: 1.0.0+1
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.3.0 <3.0.0"
|
sdk: ">=2.6.0 <3.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
cloud_firestore: ^0.13.0
|
||||||
cupertino_icons: ^0.1.2
|
cupertino_icons: ^0.1.2
|
||||||
|
firebase_auth: ^0.15.0
|
||||||
|
firebase_core: ^0.4.3
|
||||||
|
google_sign_in: ^4.4 0
|
||||||
|
json_annotation: ^3.0.0
|
||||||
provider: ^4.0.0
|
provider: ^4.0.0
|
||||||
uuid: ^2.0.0
|
uuid: ^2.0.0
|
||||||
|
charts_flutter: ^0.9.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
test: any
|
build_runner: ^1.8.0
|
||||||
|
json_serializable: ^3.3.0
|
||||||
|
test: ^1.14.0
|
||||||
|
grinder: ^0.8.4
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'package:web_dashboard/src/api/api.dart';
|
||||||
|
import 'package:web_dashboard/src/utils/chart_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('chart utils', () {
|
||||||
|
test('totals entries by day', () async {
|
||||||
|
var entries = [
|
||||||
|
Entry(10, DateTime(2020, 3, 1)),
|
||||||
|
Entry(10, DateTime(2020, 3, 1)),
|
||||||
|
Entry(10, DateTime(2020, 3, 2)),
|
||||||
|
];
|
||||||
|
var totals = entryTotalsByDay(entries, 2, today: DateTime(2020, 3, 2));
|
||||||
|
expect(totals, hasLength(3));
|
||||||
|
expect(totals[1].value, 20);
|
||||||
|
expect(totals[2].value, 10);
|
||||||
|
});
|
||||||
|
test('days', () async {
|
||||||
|
expect(
|
||||||
|
DateTime.utc(2020, 1, 3).difference(DateTime.utc(2020, 1, 2)).inDays,
|
||||||
|
1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. 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:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
|
import 'package:grinder/grinder.dart';
|
||||||
|
|
||||||
|
void main(List<String> args) => grind(args);
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void runSkia() {
|
||||||
|
run('flutter',
|
||||||
|
arguments:
|
||||||
|
'run -d web --web-port=5000 --release --dart-define=FLUTTER_WEB_USE_SKIA=true lib/main.dart '
|
||||||
|
.split(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void runWeb() {
|
||||||
|
run('flutter',
|
||||||
|
arguments: 'run -d web --web-port=5000 lib/main.dart '.split(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void runMock() {
|
||||||
|
run('flutter',
|
||||||
|
arguments: 'run -d web --web-port=5000 lib/main_mock.dart '.split(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void runMockSkia() {
|
||||||
|
run('flutter',
|
||||||
|
arguments:
|
||||||
|
'run -d web --web-port=5000 --release --dart-define=FLUTTER_WEB_USE_SKIA=true lib/main_mock.dart'
|
||||||
|
.split(' '));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void test() {
|
||||||
|
TestRunner().testAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DefaultTask()
|
||||||
|
@Depends(test, copyright)
|
||||||
|
void build() {
|
||||||
|
Pub.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void clean() => defaultClean();
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
void generate() {
|
||||||
|
Pub.run('build_runner', arguments: ['build']);
|
||||||
|
}
|
||||||
|
|
||||||
|
const _copyright =
|
||||||
|
'''// Copyright 2020, the Flutter project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.''';
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
Future copyright() async {
|
||||||
|
var files = <File>[];
|
||||||
|
await for (var file in _filesWithoutCopyright()) {
|
||||||
|
files.add(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.isNotEmpty) {
|
||||||
|
log('Found Dart files without a copyright header:');
|
||||||
|
for (var file in files) {
|
||||||
|
log(file.toString());
|
||||||
|
}
|
||||||
|
fail('run "grind fix-copyright" to add copyright headers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Task()
|
||||||
|
Future fixCopyright() async {
|
||||||
|
await for (var file in _filesWithoutCopyright()) {
|
||||||
|
var contents = await file.readAsString();
|
||||||
|
await file.writeAsString(_copyright + '\n\n' + contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<File> _filesWithoutCopyright() async* {
|
||||||
|
var set = FileSet.fromDir(Directory('.'), recurse: true);
|
||||||
|
var dartFiles =
|
||||||
|
set.files.where((file) => path.extension(file.path) == '.dart');
|
||||||
|
|
||||||
|
for (var file in dartFiles) {
|
||||||
|
var firstThreeLines = await file
|
||||||
|
.openRead()
|
||||||
|
.transform(utf8.decoder)
|
||||||
|
.transform(LineSplitter())
|
||||||
|
.take(3)
|
||||||
|
.fold<String>('', (previous, element) {
|
||||||
|
if (previous == '') return element;
|
||||||
|
return previous + '\n' + element;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (firstThreeLines != _copyright) {
|
||||||
|
yield file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Your web app's Firebase configuration
|
||||||
|
var firebaseConfig = {
|
||||||
|
apiKey: "",
|
||||||
|
authDomain: "",
|
||||||
|
databaseURL: "",
|
||||||
|
projectId: "<YOUR_PROJECT_ID>",
|
||||||
|
storageBucket: "",
|
||||||
|
messagingSenderId: "",
|
||||||
|
appId: ""
|
||||||
|
};
|
||||||
|
// Initialize Firebase
|
||||||
|
firebase.initializeApp(firebaseConfig);
|
@ -0,0 +1,11 @@
|
|||||||
|
// Copyright 2019 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('Empty test', (tester) async {
|
||||||
|
expect(1, 1);
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue