I encountered this error regarding null safety and I could not solve it
HomeModel? homeModel;
Map<int, bool> favorites = {};
void getHomeData() {
emit(ShopLoadingHomeDataState());
DioHelper.getData(
url: HOME,
token: token,
).then((value) {
homeModel = HomeModel.fromJson(value?.data);
printFullText(homeModel!.data!.banners[0].image!);
print(homeModel?.status);
homeModel!.data!.products.forEach((element) {
favorites.addAll({
element.id! : element.inFavorites!,
});
});
emit(ShopSuccessHomeDataState());
});
Here, an error occurs
backgroundColor: ShopCubit.get(context).favorites[model.id] ? defaultColor : Colors.grey ,
And say :
"A nullable expression can't be used as a condition. Try checking that the value isn't 'null' before using it as a condition."
And:
"Error: A value of type 'bool?' can't be assigned to a variable of type 'bool' because 'bool?' is nullable and 'bool' isn't"
please help me