-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add edit delete user - Using Bloc #4
base: assignment-part3
Are you sure you want to change the base?
Conversation
|
||
void _onAddingUser(AddingUser event, Emitter<UserState> emit) async { | ||
emit(UserListLoading()); | ||
await _addUser(event.newUser, emit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have already created one function to handle event. There is no need to create another one.
|
||
void _onUpdatingUser(UpdatingUser event, Emitter<UserState> emit) async { | ||
emit(UserListLoading()); | ||
await _updateUser(event.index, event.updatedUser, emit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
).then((newUser) { | ||
if (newUser != null) { | ||
userBloc.add(AddingUser(newUser)); | ||
ScaffoldMessenger.of(context).showSnackBar( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it fails?
).then((updatedUser) { | ||
if (updatedUser != null) { | ||
userBloc.add(UpdatingUser(index, updatedUser)); | ||
ScaffoldMessenger.of(context).showSnackBar( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Description
I implemented the transition from using the Riverpod package to the Bloc package, aiming for a cleaner architecture and better organization of files and folders for the bloc.
Clean Architecture Setup: I structured the files and folders following the principles of clean architecture, ensuring separation of concerns and easy navigation.
Constants for Images: All the images used across different screens were added to a
Constants
class, making it easier to manage and reference them.User Repository: I created a
UserRepository
class responsible for fetching the list of user data.Bloc Implementation: I developed a bloc architecture consisting of event, states, and a user bloc file.
Events: Events were defined for adding, updating, deleting, and reloading the page.
States: The states included loading, loaded, and error states to handle different scenarios.
Random Success/Failure: In the
UserBloc
, I introduced random chances for both success and failure scenarios to mimic real-world behavior.Loading State Handling: Loading states were added for the user list screen, edit user screen, and add user screen to provide visual feedback to users.
Snackbar Feedback: Snackbar messages were implemented to notify users when a list is added, updated, or deleted successfully.
Retry Button: A retry button was incorporated to allow users to retry an action whenever an error state occurs.
Separation of Widgets: The card widget was separated into a new file to enhance code readability and maintainability.
BlocProvider Setup: I utilized
BlocProvider
in the main.dart file to provide provider scope for updating, adding, or deleting an action on a particular event.Screenshot
Images are added in sequential order while using the app.
PR Checklist