From 31ae45dfdd2a05344f70efa8e4cb81eb209a168d Mon Sep 17 00:00:00 2001 From: dbastrikin Date: Mon, 9 Mar 2026 23:22:58 +0200 Subject: [PATCH] fix: use dialog builder context for Navigator.pop in dialogs/sheets Passing the outer widget context to Navigator.pop() inside a dialog or bottom sheet builder caused GoRouter to pop a page route instead of the modal, triggering the "no pages left to show" assertion. Affects _showChangeDialog and _confirmGenerate in menu_screen.dart, and _showAddMenu bottom sheet in products_screen.dart. Co-Authored-By: Claude Sonnet 4.6 --- client/lib/features/menu/menu_screen.dart | 12 ++++++------ client/lib/features/products/products_screen.dart | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/client/lib/features/menu/menu_screen.dart b/client/lib/features/menu/menu_screen.dart index 2db19fa..f6f44a3 100644 --- a/client/lib/features/menu/menu_screen.dart +++ b/client/lib/features/menu/menu_screen.dart @@ -287,19 +287,19 @@ class _MealRow extends ConsumerWidget { void _showChangeDialog(BuildContext context, WidgetRef ref) { showDialog( context: context, - builder: (_) => AlertDialog( + builder: (ctx) => AlertDialog( title: Text('Изменить ${slot.mealLabel.toLowerCase()}?'), content: const Text( 'Удалите текущий рецепт из слота — новый появится после следующей генерации.'), actions: [ TextButton( - onPressed: () => Navigator.pop(context), + onPressed: () => Navigator.pop(ctx), child: const Text('Отмена'), ), if (slot.recipe != null) TextButton( onPressed: () async { - Navigator.pop(context); + Navigator.pop(ctx); await ref .read(menuProvider(week).notifier) .deleteItem(slot.id); @@ -331,18 +331,18 @@ class _GenerateFab extends ConsumerWidget { void _confirmGenerate(BuildContext context, WidgetRef ref) { showDialog( context: context, - builder: (_) => AlertDialog( + builder: (ctx) => AlertDialog( title: const Text('Сгенерировать меню?'), content: const Text( 'Gemini составит меню на неделю с учётом ваших продуктов и целей. Текущее меню будет заменено.'), actions: [ TextButton( - onPressed: () => Navigator.pop(context), + onPressed: () => Navigator.pop(ctx), child: const Text('Отмена'), ), FilledButton( onPressed: () { - Navigator.pop(context); + Navigator.pop(ctx); ref.read(menuProvider(week).notifier).generate(); }, child: const Text('Сгенерировать'), diff --git a/client/lib/features/products/products_screen.dart b/client/lib/features/products/products_screen.dart index e23c8c1..f70be37 100644 --- a/client/lib/features/products/products_screen.dart +++ b/client/lib/features/products/products_screen.dart @@ -8,7 +8,7 @@ import 'product_provider.dart'; void _showAddMenu(BuildContext context) { showModalBottomSheet( context: context, - builder: (_) => SafeArea( + builder: (ctx) => SafeArea( child: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -16,7 +16,7 @@ void _showAddMenu(BuildContext context) { leading: const Icon(Icons.edit_outlined), title: const Text('Добавить вручную'), onTap: () { - Navigator.pop(context); + Navigator.pop(ctx); context.push('/products/add'); }, ), @@ -24,7 +24,7 @@ void _showAddMenu(BuildContext context) { leading: const Icon(Icons.document_scanner_outlined), title: const Text('Сканировать чек или фото'), onTap: () { - Navigator.pop(context); + Navigator.pop(ctx); context.push('/scan'); }, ),