From 5b8aec57096ccfe1d795a5db46d4520394399f69 Mon Sep 17 00:00:00 2001 From: tuanha Date: Mon, 28 Jun 2021 21:07:36 +0700 Subject: [PATCH] [Reminder State] Fix bug undeclared isLoading for props func and update func and Forgot call InitialEvent() --- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + ios/Podfile | 41 +++++++++++ ios/Podfile.lock | 22 ++++++ ios/Runner.xcodeproj/project.pbxproj | 68 +++++++++++++++++++ .../contents.xcworkspacedata | 3 + lib/bloc/reminder_bloc.dart | 31 ++++++--- lib/bloc/reminder_state.dart | 10 ++- lib/main.dart | 3 +- lib/widget/reminder_widget.dart | 2 +- 10 files changed, 163 insertions(+), 19 deletions(-) create mode 100644 ios/Podfile create mode 100644 ios/Podfile.lock diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index 592ceee..e8efba1 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 592ceee..399e934 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 0000000..1e8c3c9 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,41 @@ +# 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 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 + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + 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_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/ios/Podfile.lock b/ios/Podfile.lock new file mode 100644 index 0000000..b88a118 --- /dev/null +++ b/ios/Podfile.lock @@ -0,0 +1,22 @@ +PODS: + - Flutter (1.0.0) + - path_provider (0.0.1): + - Flutter + +DEPENDENCIES: + - Flutter (from `Flutter`) + - path_provider (from `.symlinks/plugins/path_provider/ios`) + +EXTERNAL SOURCES: + Flutter: + :path: Flutter + path_provider: + :path: ".symlinks/plugins/path_provider/ios" + +SPEC CHECKSUMS: + Flutter: 0e3d915762c693b495b44d77113d4970485de6ec + path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c + +PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c + +COCOAPODS: 1.10.1 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index b97456d..718bcec 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; + 43F100E74DF9EE5392ECBC04 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D5B53B5E0EFECB7FF9E2C8E5 /* Pods_Runner.framework */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -29,12 +30,15 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 013E1FB17FFCABBA6E6EF7D4 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; + 463816E249964AE719E9B486 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; + 82C7ABB995EA8D111F2C8790 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -42,6 +46,7 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + D5B53B5E0EFECB7FF9E2C8E5 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,12 +54,24 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 43F100E74DF9EE5392ECBC04 /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 66069B8D710F5A145EBF4AF8 /* Pods */ = { + isa = PBXGroup; + children = ( + 013E1FB17FFCABBA6E6EF7D4 /* Pods-Runner.debug.xcconfig */, + 82C7ABB995EA8D111F2C8790 /* Pods-Runner.release.xcconfig */, + 463816E249964AE719E9B486 /* Pods-Runner.profile.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -72,6 +89,8 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, + 66069B8D710F5A145EBF4AF8 /* Pods */, + C3F189B13157C4F9111FF2D6 /* Frameworks */, ); sourceTree = ""; }; @@ -98,6 +117,14 @@ path = Runner; sourceTree = ""; }; + C3F189B13157C4F9111FF2D6 /* Frameworks */ = { + isa = PBXGroup; + children = ( + D5B53B5E0EFECB7FF9E2C8E5 /* Pods_Runner.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -105,12 +132,14 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( + E99029EFDA4A8C7DBA1FE23F /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + C147A0DB71008B5B1253BD90 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -197,6 +226,45 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + C147A0DB71008B5B1253BD90 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Embed Pods Frameworks"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + E99029EFDA4A8C7DBA1FE23F /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/ios/Runner.xcworkspace/contents.xcworkspacedata b/ios/Runner.xcworkspace/contents.xcworkspacedata index 1d526a1..21a3cc1 100644 --- a/ios/Runner.xcworkspace/contents.xcworkspacedata +++ b/ios/Runner.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + diff --git a/lib/bloc/reminder_bloc.dart b/lib/bloc/reminder_bloc.dart index 5445c7e..1030ad0 100644 --- a/lib/bloc/reminder_bloc.dart +++ b/lib/bloc/reminder_bloc.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:bloc/bloc.dart'; import 'package:demo_hive/bloc/reminder_event.dart'; import 'package:demo_hive/bloc/reminder_state.dart'; @@ -6,24 +8,30 @@ import 'package:demo_hive/domain/use_case/reminders_use_case.dart'; import 'package:flutter/cupertino.dart'; class ReminderBloc extends Bloc { - final RemindersUseCase remindersUseCase; + ReminderBloc({@required this.remindersUseCase}); + List reminders = []; @override Stream mapEventToState(ReminderEvent event) async* { if (event is InitialEvent) { yield* _mapInitialEventToState(); - } else if (event is AddTitleEvent) { + } + if (event is AddTitleEvent) { yield* _mapAddTitleEventToState(event); - } else if (event is GetValueTitleEvent) { + } + if (event is GetValueTitleEvent) { yield* _mapGetValueTitleEventToState(event); - } else if (event is RemoveEvent) { + } + if (event is RemoveEvent) { yield* _mapRemoveEventToState(); - } else if (event is RemoveReminderEvent) { + } + if (event is RemoveReminderEvent) { yield* _mapRemoveReminderEventState(); - } else if (event is RemoveTitle) { + } + if (event is RemoveTitle) { yield* _mapRemoveTitleEventToState(event); } } @@ -31,7 +39,7 @@ class ReminderBloc extends Bloc { Stream _mapInitialEventToState() async* { yield state.update(isLoading: true); reminders = await remindersUseCase.getFull(); - yield state.update(list: reminders,isLoading: false); + yield state.update(list: reminders, isLoading: false); } Stream _mapAddTitleEventToState(AddTitleEvent event) async* { @@ -39,23 +47,24 @@ class ReminderBloc extends Bloc { ReminderEntity reminderEntity = ReminderEntity(title: event.title); reminders.add(reminderEntity); await remindersUseCase.addNote(reminderEntity); - yield state.update(list: reminders,isLoading:false); + log('AddTitleEvent: ${reminderEntity.title}'); + yield state.update(list: reminders, isLoading: false); } Stream _mapGetValueTitleEventToState( GetValueTitleEvent event) async* { yield state.update(isLoading: true); - yield state.update(isEmpty: event.title.isEmpty,isLoading: false); + yield state.update(isEmpty: event.title.isEmpty, isLoading: false); } Stream _mapRemoveEventToState() async* { yield state.update(isLoading: true); - yield state.update(isEmpty: true,isLoading: false); + yield state.update(isEmpty: true, isLoading: false); } Stream _mapRemoveReminderEventState() async* { yield state.update(isLoading: true); - yield state.update(isEmpty: true,isLoading: false); + yield state.update(isEmpty: true, isLoading: false); } Stream _mapRemoveTitleEventToState(RemoveTitle event) async* { diff --git a/lib/bloc/reminder_state.dart b/lib/bloc/reminder_state.dart index ea24a18..e8449ff 100644 --- a/lib/bloc/reminder_state.dart +++ b/lib/bloc/reminder_state.dart @@ -7,18 +7,16 @@ class ReminderState extends Equatable { final String title; final bool isLoading; - ReminderState({this.isEmpty, this.list, this.title,this.isLoading}); + ReminderState({this.isEmpty, this.list, this.title, this.isLoading}); ReminderState update( - {bool isEmpty, List list, String title,bool isLoading}) { + {bool isEmpty, List list, String title, bool isLoading}) { return ReminderState( + isLoading: isLoading ?? this.isLoading, isEmpty: isEmpty ?? this.isEmpty, list: list ?? this.list, title: title ?? this.title); } - List get props => [isEmpty, list]; + List get props => [isEmpty, list, this.isLoading, this.title]; } - - - diff --git a/lib/main.dart b/lib/main.dart index db746ef..1639cc9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:demo_hive/service_locator.dart'; import 'package:demo_hive/widget/reminder_widget.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'bloc/reminder_event.dart'; import 'data/data_source/local/local_init.dart'; import 'domain/use_case/reminders_use_case.dart'; @@ -40,7 +41,7 @@ class MyApp extends StatelessWidget { visualDensity: VisualDensity.adaptivePlatformDensity, ), home: BlocProvider( - create: (_) => locator(), + create: (_) => locator()..add(InitialEvent()), child: ReminderWidget()), ); } diff --git a/lib/widget/reminder_widget.dart b/lib/widget/reminder_widget.dart index 881adb7..ebe84f8 100644 --- a/lib/widget/reminder_widget.dart +++ b/lib/widget/reminder_widget.dart @@ -108,7 +108,7 @@ class _ReminderWidgetState extends State { style: TextStyle(fontSize: 18), )); } - if(state.isLoading == true){ + if (state.isLoading == true) { return CircularProgressIndicator(); } return ListView.builder(