You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Redux uses a single store to hold the entire state of the app. Flutter Bloc allows multiple BLoCs, each handling a specific aspect of the state.
Action
Actions (plain objects)
Events (classes)
In Redux, actions are plain objects dispatched to modify state. In Flutter Bloc, events are dispatched to trigger transitions to new states.
Reducer
Reducer Functions
Map<Event, State>
Reducers take actions and the current state and return a new state. In Flutter Bloc, an event triggers state transitions.
State
Store's State
Bloc’s State
Redux's store holds the entire application state. In Flutter Bloc, each Bloc manages its own piece of state.
Slice
A section of state + reducers
Bloc Cubit (or Bloc with map events)
Redux slices break down the state into manageable sections. In Flutter Bloc, Cubits are simpler alternatives to Blocs, useful when events are not necessary.
Selector
useSelector (from React-Redux)
state.select (or listen to changes)
A way to select a part of the state in React Redux. Flutter Bloc lets you listen to specific state changes using BlocListener or BlocBuilder.
Dispatch
useDispatch (React Redux)
Bloc.add(Event) or Cubit.method
Redux dispatches actions using useDispatch, while in Flutter Bloc, you dispatch events with Bloc.add(). Cubits are more direct, calling methods to update state.
Middleware
redux-thunk or redux-saga
BlocObserver or EventTransformers
Redux middleware allows async operations (API calls). Flutter Bloc has BlocObserver to track Bloc changes, and event transformers can transform incoming events.
Thunk (async actions)
redux-thunk
async* Streams
Redux uses thunks for async logic. In Flutter Bloc, you use async* in the mapEventToState method to manage async calls and streams.
Provider
Redux Provider (from React Redux)
BlocProvider
In both libraries, providers are used to expose a store (or Bloc) to a widget subtree.
The text was updated successfully, but these errors were encountered:
Redux vs Flutter Bloc Cheatsheet
useSelector
(from React-Redux)state.select
(or listen to changes)BlocListener
orBlocBuilder
.useDispatch
(React Redux)Bloc.add(Event)
orCubit.method
useDispatch
, while in Flutter Bloc, you dispatch events withBloc.add()
. Cubits are more direct, calling methods to update state.redux-thunk
orredux-saga
BlocObserver
to track Bloc changes, and event transformers can transform incoming events.redux-thunk
async*
Streamsasync*
in themapEventToState
method to manage async calls and streams.Provider
(from React Redux)BlocProvider
The text was updated successfully, but these errors were encountered: