Home > Net >  What is the difference between Cubit Basic, Cubit Equatable and Cubit Freezed?
What is the difference between Cubit Basic, Cubit Equatable and Cubit Freezed?

Time:12-28

I am starting with cubit but when i make a cubit there are 3 types like this (Cubit Basic, Cubit Equatable and Cubit Freezed)

I don't know what is the difference between them and what is special

CodePudding user response:

Cubit is a state management library for Flutter that is based on the BLoC (Business Logic Components) pattern. It helps you to separate your business logic from your user interface code and makes it easier to test and maintain your app.

There are three main types of Cubits that you can use in your Flutter app:

Cubit Basic: This is the most basic type of Cubit and is used to manage a single piece of state. It does not have any built-in support for comparing the current state to a previous state, or for creating a copy of the state.

Cubit Equatable: This type of Cubit is similar to the basic version, but it adds support for comparing the current state to a previous state using the == operator. This is useful if you need to update the UI based on changes to the state.

Cubit Freezed: This type of Cubit is similar to the equatable version, but it also includes support for creating a copy of the state using the copyWith method. This is useful if you need to make a copy of the state and modify it before updating the UI.

In general, you should use the basic version of Cubit if you only need to manage a single piece of state and don't need any advanced features like state comparison or state copying. If you need to compare the current state to a previous state or make a copy of the state, you should use the equatable or freezed versions of Cubit.

  • Related