[Reminder State] Fix bug undeclared isLoading for props func and update func and Forgot call InitialEvent()

This commit is contained in:
tuanha 2021-06-28 21:07:36 +07:00
parent a59b2830c2
commit 5b8aec5709
10 changed files with 163 additions and 19 deletions

View File

@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"

View File

@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"

41
ios/Podfile Normal file
View File

@ -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

22
ios/Podfile.lock Normal file
View File

@ -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

View File

@ -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 = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
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 = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
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 = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
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 = "<group>"; };
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
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 = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
@ -72,6 +89,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
66069B8D710F5A145EBF4AF8 /* Pods */,
C3F189B13157C4F9111FF2D6 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -98,6 +117,14 @@
path = Runner;
sourceTree = "<group>";
};
C3F189B13157C4F9111FF2D6 /* Frameworks */ = {
isa = PBXGroup;
children = (
D5B53B5E0EFECB7FF9E2C8E5 /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* 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 */

View File

@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

View File

@ -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<ReminderEvent, ReminderState> {
final RemindersUseCase remindersUseCase;
ReminderBloc({@required this.remindersUseCase});
List<ReminderEntity> reminders = [];
@override
Stream<ReminderState> 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<ReminderEvent, ReminderState> {
Stream<ReminderState> _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<ReminderState> _mapAddTitleEventToState(AddTitleEvent event) async* {
@ -39,23 +47,24 @@ class ReminderBloc extends Bloc<ReminderEvent, ReminderState> {
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<ReminderState> _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<ReminderState> _mapRemoveEventToState() async* {
yield state.update(isLoading: true);
yield state.update(isEmpty: true,isLoading: false);
yield state.update(isEmpty: true, isLoading: false);
}
Stream<ReminderState> _mapRemoveReminderEventState() async* {
yield state.update(isLoading: true);
yield state.update(isEmpty: true,isLoading: false);
yield state.update(isEmpty: true, isLoading: false);
}
Stream<ReminderState> _mapRemoveTitleEventToState(RemoveTitle event) async* {

View File

@ -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<ReminderEntity> list, String title,bool isLoading}) {
{bool isEmpty, List<ReminderEntity> list, String title, bool isLoading}) {
return ReminderState(
isLoading: isLoading ?? this.isLoading,
isEmpty: isEmpty ?? this.isEmpty,
list: list ?? this.list,
title: title ?? this.title);
}
List<Object> get props => [isEmpty, list];
List<Object> get props => [isEmpty, list, this.isLoading, this.title];
}

View File

@ -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<ReminderBloc>(),
create: (_) => locator<ReminderBloc>()..add(InitialEvent()),
child: ReminderWidget()),
);
}

View File

@ -108,7 +108,7 @@ class _ReminderWidgetState extends State<ReminderWidget> {
style: TextStyle(fontSize: 18),
));
}
if(state.isLoading == true){
if (state.isLoading == true) {
return CircularProgressIndicator();
}
return ListView.builder(