I have a Map<int,int>
inside my State
which I want to update at some point. Currently I am updating the map like this:
final updatedMap = Map<int, int>.from(state.skipViewsWithSkipValues);
updatedMap[state.currentViewIndex] = _viewsIfMnp.length;
emit(
state.copyWith(
skipViewsWithSkipValues: updatedMap,
),
);
And this works, but seems quite dirty. What is the "clean" way to update a map
inside a state
of a cubit
?
IMO this is the right way to do it, if you're discussing the code readability, you may utilize
Map.of
instead ofMap.from
, which uses the same key and value types, so no need to pass the generic types. You may also use the cascade operator mixed with the subscript access, like so: