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
Hello, what I want to suggest is a bettter support for generics. You know, sometimes Dart automatically infers the type from the variables, but in some cases, it can't, such as in Bloc/Cubits.
classCounterCubitextendsCubit<int> {
CounterCubit() :super(0);
}
classExample<MyCubitextendsCubit<State>, State> {
finalMyCubit cubit;
Example(this.cubit);
Stateget state => cubit.state;
}
voidmain(List<String> args) async {
final example =Example(CounterCubit());
example.cubit; // it is CounterCubit
example.state; // it is Object? or dynamic.
}
Lets say that we have a class like this. The type of example.cubit is inferred correctly, but example.state is not.
To infer the type correctly, we have to provide the type manuelly.
voidmain(List<String> args) async {
final example =Example<CounterCubit, int>(CounterCubit());
example.cubit; // it is CounterCubit
example.state; // it is Object? or dynamic.
}
The text was updated successfully, but these errors were encountered:
How would you want this to work? The code doesn't declare any base class for State, so if you omit it Dart has nothing to go off of. It's able to infer CounterCubit and not just Cubit because you declared MyCubit extends Cubit<State> and you passed in a CounterCubit as the parameter. But there's no equivalent "hint" for the type of State. In other words, I, as a human reader, have no idea that you want int because it's not actually in your code... until you manually put it in.
Unless you're asking that Dart recognize the link between MyCubit and State. You'd probably be interested in #620 and #102, which deal with the same request.
Yeah, I am asking about the link between CounterCubit and int. Let me close this one and discuss it on #620 and #102
How would you want this to work? The code doesn't declare any base class for State, so if you omit it Dart has nothing to go off of. It's able to infer CounterCubit and not just Cubit because you declared MyCubit extends Cubit<State> and you passed in a CounterCubit as the parameter. But there's no equivalent "hint" for the type of State. In other words, I, as a human reader, have no idea that you want int because it's not actually in your code... until you manually put it in.
Unless you're asking that Dart recognize the link between MyCubit and State. You'd probably be interested in #620 and #102, which deal with the same request.
Hello, what I want to suggest is a bettter support for generics. You know, sometimes Dart automatically infers the type from the variables, but in some cases, it can't, such as in Bloc/Cubits.
Lets say that we have a class like this. The type of example.cubit is inferred correctly, but example.state is not.
To infer the type correctly, we have to provide the type manuelly.
The text was updated successfully, but these errors were encountered: