前提
go_routerを使用しています
エラー
You have popped the last page off of the stack, there are no pages left to show
エラー発生箇所
以下のようなダイアログで Navigator.pop(context)
を実行したところ上記エラーが発生島下
await showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text('これはダイアログです'),
actions: [
TextButton(
onPressed: () async {
Navigator.pop(context);
},
child: const Text('戻る'),
),
],
);
},
);
解決方法
GoRouter.of(context).pop()
を使う
await showDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text('これはダイアログです'),
actions: [
TextButton(
onPressed: () async {
GoRouter.of(context).pop(); // これ
},
child: const Text('戻る'),
),
],
);
},
);