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:
@@ -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('Сгенерировать'),
|
||||
|
||||
@@ -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');
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user