[Part 3]
nishu767 opened this issue · comments
CounterState({@required this.counterValue, this.wasIncremented});
this shows an error and it works fine when i remove '@' from required, it also asks to add required to 'this.wasIncremented' .
means CounterState({required this.counterValue, required this.wasIncremented}); works fine ,
but in counter_cubit it asks to pass the required parameter of 'this.wasIncremented' in countercubit()
is it same as
part of 'counter_cubit.dart';
class CounterState {
int counterValue;
bool wasIncremented;
CounterState({
required this.counterValue,
this.wasIncremented = true,
});
}
That's because of dart's null safety feature, the way i worked around it was adding a ? to the variable wasIncremented like this:
class CounterState extends Equatable{
int counterValue;
bool? wasIncremented;
CounterState({
required this.counterValue,
this.wasIncremented,
});
@OverRide
List<Object?> get props => [counterValue,wasIncremented];
}