I am getting error as soon as I add async keyword to the blocbuilder function to use await later. Here is my code snippet:
BlocBuilder<ProductCubit, CollectionState>(
builder: (context, state) {
if (state is CollectionSuccess<ProductModel>) {
var productModel = state.models.first;
return BlocBuilder<AuthCubit, AuthState>(
builder: (context, state) async { // async added here gives error
if (state is AuthSuccess) {
var userData = state.userData;
var docRef = userData.getActivePlan(
productModel); //await? and async?
return BlocProvider(
create: (context) => StripeProductDocumentCubit(
documentRef: docRef as DocumentReference<
Map<String, dynamic>>),
child: BlocBuilder<StripeProductDocumentCubit,
DocumentState>(
builder: (context, state) {
if (state is DocumentSuccess<
StripeProductModel>) {
var stripeDocumentModel = state.model;
return BlocConsumer<ParticipantsCubit,
ParticipantState>(
listener: (context, state) {},
builder: (context, state) {
return state is DatabaseSuccess
? Row(
mainAxisAlignment:
MainAxisAlignment.start,
mainAxisSize:
MainAxisSize.min,
crossAxisAlignment:
CrossAxisAlignment.end,
children: [
Text(
'Active participants: ${state.participantsCount} / ${stripeDocumentModel.metaData['maxParticipants']}'),
])
: Container();
},
);
} else {
return const CircularProgressIndicator();
}
},
));
} else {
return const CircularProgressIndicator();
}
},
);
} else {
return const CircularProgressIndicator();
}
},
),
The error says ‘The argument type ‘Future Function(BuildContext, AuthState)’ can’t be assigned to the parameter type ‘Widget Function(BuildContext, AuthState)’. Is there a fix?