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?

PushReplacementを使うと黒い画面に戻ることがあるというお話

Posted at

エラー

  • 昔話なので詳細なコードを忘れてしまったが、pushReplacement()を用いて画面遷移を定義。
  • 呼び出し先から呼び出し元に戻る際に、元の画面がなく、黒い画面へと遷移する。
parent.dart
// push()を用いて画面遷移
Navigator.of(context).push(
  MaterialPageRoute(builder: (context) => ChildScreenA()),
);

// pushReplacementを用いて画面遷移
Navigator.of(context).pushReplacement(
  MaterialPageRoute(builder: (context) => ChildScreenB()),
);

原因

  • pushpushReplacementには明確な挙動の違いがあるため。
push pushReplacement
遷移元画面の上に画面を重ねる 遷移元画面を破棄して画面を表示する
  • pushの場合だと画面がn層重なる可能性があるのに対して、pushReplacementは必ず1層しか表示されない。
  • 画面遷移に失敗すると、呼び出す画面が存在しないために黒い画面が表示されることがある。
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?