0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Flutter] You have popped the last page off of the stack, there are no pages left to show

Posted at

前提

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('戻る'),
        ),
      ],
    );
  },
);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?