fix-errors

This commit is contained in:
mso7nueh
2026-06-01 12:42:22 +03:00
parent af3b40d5f2
commit 85d32dd3a1
8 changed files with 82 additions and 18 deletions

View File

@@ -116,6 +116,9 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
builder: (context, state) {
if (state is DiaryStateLoaded) {
int mealIndex = state.selectedMeal - 1;
if (mealIndex < 0 || mealIndex >= state.diary.meals.length) {
return const SizedBox.shrink();
}
final photos = state.diary.meals[mealIndex].photos;
// BUG-5 fix: сбросить индекс, если он вышел за пределы
// (например, после переключения на meal с меньшим числом фото)

View File

@@ -20,6 +20,9 @@ class _ProductsListWidgetState extends State<ProductsListWidget> {
builder: (BuildContext context, DiaryState state) {
if (state is DiaryStateLoaded) {
int mealIndex = state.selectedMeal - 1;
if (mealIndex < 0 || mealIndex >= state.diary.meals.length) {
return const SizedBox.shrink();
}
final portions = state.diary.meals[mealIndex].portions;
return Column(
mainAxisSize: MainAxisSize.min,
@@ -35,6 +38,9 @@ class _ProductsListWidgetState extends State<ProductsListWidget> {
}
if (state is DiaryStateLoadedTomorrowWithDiet) {
int mealIndex = state.selectedMeal - 1;
if (mealIndex < 0 || mealIndex >= state.diary.meals.length) {
return const SizedBox.shrink();
}
final portions = state.diary.meals[mealIndex].portions;
return Column(
mainAxisSize: MainAxisSize.min,

View File

@@ -87,6 +87,11 @@ class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
return BlocBuilder<DiaryCubit, DiaryState>(
builder: (context, state) {
if (state is DiaryStateLoaded) {
final meals = state.diary.meals;
final mealIndex = state.selectedMeal - 1;
if (mealIndex < 0 || mealIndex >= meals.length) {
return const SizedBox.shrink();
}
return Column(
children: [
const CustomDivider(),