🧟

you have popped the last page off of the stack, there are no pages lef

JboyHashimoto2023/02/15に公開

go_routerでpopできない?

go_routershowDialogを閉じるとエラーが発生した😱

エラーコード

_assertionerror ('package:go_router/src/delegate.dart': failed assertion:
you have popped the last page off of the stack, there are no pages left to show)

このコードをonPressedの中に書くと、エラーが発生した!

Navigator.of(context).pop(context);

こちらの記事を参考にしたら解決できた!
https://stackoverflow.com/questions/74284129/gorouter-can-i-push-2-pages-at-once

コードを修正すると実行できた!

AlertDialog(
  title: Text("This is the title"),
    content: Text("This is the content"),
    actions: [
    TextButton(
     child: Text("Cancel"),
     onPressed: () {
  // Navigator.of(context).pop(context);
	  GoRouter.of(context).pop();// こちらのコードに変更.
	},
      ),
      TextButton(
	child: Text("OK"),
	onPressed: () => print('OK'),
      ),
    ],
  );

まとめ

最近、go_routerを使うようになって画面遷移のエラーによくハマります!
画面遷移のコードは、ダイアログやボトムシート、Widgetによって違うみたいです。

Flutter大学

Flutter大学はFlutterエンジニアに特化した学習コミュニティです! 初心者から中上級者まで幅広く在籍し、切磋琢磨しています! 入会をご希望の方はこちらから→ https://flutteruniv.com

Discussion

ログインするとコメントできます