Reputation: 122
In Flutter, when I call the cubit method below, the state is getting emitted twice.
Can someone help me find what's wrong with my code?
Cubit class:
class AlertCubit extends Cubit<AlertState> {
AlertCubit() : super(AlertInitial());
void alert(InfoAlertData alertInfo) {
emit(AlertInitial());
**emit(NewAlert(alertInfo));**
}
}
Where I call this function from another cubit:
class CustomersCubit extends Cubit<CustomersState> {
CustomersCubit(
{required this.alertCubit,
})
: super(CustomersInitial());
final AlertCubit alertCubit;
///removed irrelevant code
void markMissing(int loanId) async {
if (collectionCubit.active) {
} else {
**alertCubit.alert(InfoAlerts.startCollect);**
}
}
///removed irrelevant code
}
I passed cubit as a parameter in main:
///removed irrelevant code
return MultiBlocProvider(
providers: [
BlocProvider(
create: (_) => AlertCubit(),
),
BlocProvider(
create: (BuildContext cusContext) => CustomersCubit(
**alertCubit: BlocProvider.of<AlertCubit>(cusContext),**
),
),
///removed irrelevant code
I am new to flutter and bloc; any help is appreciated
Upvotes: 1
Views: 395