Skip to content
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

Open
wants to merge 3 commits into
base: assignment-part3
Choose a base branch
from

Conversation

adityazanzane-coditas
Copy link
Owner

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.

  1. Clean Architecture Setup: I structured the files and folders following the principles of clean architecture, ensuring separation of concerns and easy navigation.

  2. Constants for Images: All the images used across different screens were added to a Constants class, making it easier to manage and reference them.

  3. User Repository: I created a UserRepository class responsible for fetching the list of user data.

  4. Bloc Implementation: I developed a bloc architecture consisting of event, states, and a user bloc file.

  5. Events: Events were defined for adding, updating, deleting, and reloading the page.

  6. States: The states included loading, loaded, and error states to handle different scenarios.

  7. Random Success/Failure: In the UserBloc, I introduced random chances for both success and failure scenarios to mimic real-world behavior.

  8. 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.

  9. Snackbar Feedback: Snackbar messages were implemented to notify users when a list is added, updated, or deleted successfully.

  10. Retry Button: A retry button was incorporated to allow users to retry an action whenever an error state occurs.

  11. Separation of Widgets: The card widget was separated into a new file to enhance code readability and maintainability.

  12. 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.

Screenshot 2024-04-14 at 9 35 07 AM Screenshot 2024-04-14 at 9 33 00 AM Screenshot 2024-04-14 at 9 34 21 AM Screenshot 2024-04-14 at 9 36 47 AM Screenshot 2024-04-14 at 9 37 59 AM Screenshot 2024-04-14 at 9 36 01 AM Screenshot 2024-04-14 at 9 42 27 AM Screenshot 2024-04-14 at 9 42 02 AM

PR Checklist

  • Build success
  • Tested


void _onAddingUser(AddingUser event, Emitter<UserState> emit) async {
emit(UserListLoading());
await _addUser(event.newUser, emit);

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);

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(

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(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants