Comments (5)
What do you mean? It's one extra line of code haha. If you want, you can make your own custom cubit that does this for you like:
abstract class MyCubit<T> extends Cubit<T> {
MyCubit(this.initialState) : super(initialState);
final T initialState;
}
Then you can make your cubits all extend MyCubit
instead:
class CounterCubit extends MyCubit<int> {
CounterCubit() : super(0);
void someMethod() {
// you can now access the initial state via `initialState`
}
}
This solution is the same amount of code as you would currently write minus the MyCubit
class (which is a one time thing) 👍
from cubit.
Hi @pedromassango 👋
It's not cubit's responsibility to cache your initial state.
You can have a factory constructor on your freezed data class
factory LanguageState.initial() => LanguageState(
languages: [],
isLoadingLanguages: true,
loadLanguageFailure: null,
);
and use it to initialize your cubit or to emit it again when needed.
LanguageCubit() : super(LanguageState.initial());
emit(LanguageState.initial());
Hope that helps 👍
from cubit.
Hi @pedromassango 👋
You can add an initialState
property to your cubit
as needed 👍
class CounterCubit extends Cubit<int> {
CounterCubit(this.initialState) : super(initialState);
final int initialState;
}
Hope that helps 👍
from cubit.
Hi @pedromassango 👋
You can add an
initialState
property to yourcubit
as needed 👍class CounterCubit extends Cubit<int> { CounterCubit(this.initialState) : super(initialState); final int initialState; }Hope that helps 👍
I mean, the cubit to preserve the initial state passed into it. The solution you suggested works but:
- You need to provide it via constructor
- You need to write a lot fo code for every Cubit in the project when neccessary.
from cubit.
I get it 👍
from cubit.
Related Issues (18)
- Thoughts HOT 3
- Allow cubit to override the provider HOT 2
- Why do we need to specify the cobit state type in the cubitBuilder? HOT 2
- Cubit Delegate/Supervisor missing? HOT 1
- Provide a example in how to emit a complex object state HOT 2
- CubitListener behaviour skips(1) HOT 5
- CubitModule? HOT 3
- Observer in Cubit? HOT 3
- Snippets HOT 1
- [DISCUSSION] Should Cubit expose Stream API? HOT 12
- [HELP] Emit state from a stream in repository HOT 2
- Emitted state not received by CubitBuilder HOT 20
- Scale cubit with bloc capabilities HOT 4
- ReplayCubit - List with mutated state can not be redo / undo HOT 11
- What scopes API should look like? HOT 5
- [PROPOSAL] Merge Cubit into Bloc HOT 32
- Get state without builder HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cubit.