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 <noreply@anthropic.com>
This commit is contained in:
dbastrikin
2026-03-09 23:22:58 +02:00
parent 0567d90784
commit 31ae45dfdd
2 changed files with 9 additions and 9 deletions

View File

@@ -287,19 +287,19 @@ class _MealRow extends ConsumerWidget {
void _showChangeDialog(BuildContext context, WidgetRef ref) { void _showChangeDialog(BuildContext context, WidgetRef ref) {
showDialog( showDialog(
context: context, context: context,
builder: (_) => AlertDialog( builder: (ctx) => AlertDialog(
title: Text('Изменить ${slot.mealLabel.toLowerCase()}?'), title: Text('Изменить ${slot.mealLabel.toLowerCase()}?'),
content: const Text( content: const Text(
'Удалите текущий рецепт из слота — новый появится после следующей генерации.'), 'Удалите текущий рецепт из слота — новый появится после следующей генерации.'),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(ctx),
child: const Text('Отмена'), child: const Text('Отмена'),
), ),
if (slot.recipe != null) if (slot.recipe != null)
TextButton( TextButton(
onPressed: () async { onPressed: () async {
Navigator.pop(context); Navigator.pop(ctx);
await ref await ref
.read(menuProvider(week).notifier) .read(menuProvider(week).notifier)
.deleteItem(slot.id); .deleteItem(slot.id);
@@ -331,18 +331,18 @@ class _GenerateFab extends ConsumerWidget {
void _confirmGenerate(BuildContext context, WidgetRef ref) { void _confirmGenerate(BuildContext context, WidgetRef ref) {
showDialog( showDialog(
context: context, context: context,
builder: (_) => AlertDialog( builder: (ctx) => AlertDialog(
title: const Text('Сгенерировать меню?'), title: const Text('Сгенерировать меню?'),
content: const Text( content: const Text(
'Gemini составит меню на неделю с учётом ваших продуктов и целей. Текущее меню будет заменено.'), 'Gemini составит меню на неделю с учётом ваших продуктов и целей. Текущее меню будет заменено.'),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(ctx),
child: const Text('Отмена'), child: const Text('Отмена'),
), ),
FilledButton( FilledButton(
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(ctx);
ref.read(menuProvider(week).notifier).generate(); ref.read(menuProvider(week).notifier).generate();
}, },
child: const Text('Сгенерировать'), child: const Text('Сгенерировать'),

View File

@@ -8,7 +8,7 @@ import 'product_provider.dart';
void _showAddMenu(BuildContext context) { void _showAddMenu(BuildContext context) {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
builder: (_) => SafeArea( builder: (ctx) => SafeArea(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
@@ -16,7 +16,7 @@ void _showAddMenu(BuildContext context) {
leading: const Icon(Icons.edit_outlined), leading: const Icon(Icons.edit_outlined),
title: const Text('Добавить вручную'), title: const Text('Добавить вручную'),
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(ctx);
context.push('/products/add'); context.push('/products/add');
}, },
), ),
@@ -24,7 +24,7 @@ void _showAddMenu(BuildContext context) {
leading: const Icon(Icons.document_scanner_outlined), leading: const Icon(Icons.document_scanner_outlined),
title: const Text('Сканировать чек или фото'), title: const Text('Сканировать чек или фото'),
onTap: () { onTap: () {
Navigator.pop(context); Navigator.pop(ctx);
context.push('/scan'); context.push('/scan');
}, },
), ),