I should use final, but what if I need to modify something instead?

44 views Asked by At

I'm new with equatable and I've red that all the parameters in my model must be final, but I don't know how to deal with it... What if i need to modify one of these parameters? I've a view where you can add new restaurants to a list, and this list will be saved in Firestore. I'm using flutter bloc, so I add a CreateRestaurantFirebaseEvent, and this is what happens in my mapEventToState:

if (event is CreateRestaurantFirebaseEvent) 
      await _databaseService.createRestaurant(event.restaurant, event.user);
      List<Restaurant> restaurantsList = await _databaseService
          .loadRestaurantsList(event.user.restaurantsIDsList);
      yield LoadedRestaurantsListState(restaurantsList);
    }

and in my database_service:

  Future createRestaurant(Restaurant restaurant, User user) async {
    restaurant.adminId = user.id;
    DocumentReference restaurantDoc =
        await restaurantCollection.add(restaurant.toMap());
    user.restaurantsIDsList.add(restaurantDoc.id);
    updateUser(user);
    restaurant.id = restaurantDoc.id;
    return restaurant;
  }

So, I've to update my restaurant with some props, but if I've only final props I can't do that. What is the best practice? I need equatable, otherwise my bloc won't work correctly.

Thanks in advance

0

There are 0 answers