본문 바로가기
기초다지기/Flutter&Dart

flutter Navigator 메서드

by 김빵그 2023. 10. 25.

Navigator 메서드

1) Push

  • 새로운 화면을 스택에 추가한다. 새 화면을 현재 화면 위에 푸시하여 사용자가 새 화면을 볼 수 있게 한다
Navigator.of(context).push(route)
Navigator.of(context).push(MaterialPageRoute(builder: (context) => YourScreen()))

2) pushNamed 

  • 지정된 라우트 이름에 해당하는 화면을 스택에 추가한다
Navigator.of(context).pushNamed(routeName)

3) pushReplacement / pushReplacementNamed

  • 현재 화면을 스택에서 제거하고 새 화면을 추가
  • 이전화면으로 돌아가지 못하고, 새로운 화면으로 전환할 때 사용한다
Navigator.of(context).pushReplacement(route)
Navigator.of(context).pushReplacementNamed(routeName)

4) pop 

  • 현재 화면을 스택에서 제거하고 이전화면으로 돌아간다
  • 사용가자 이전 화면으로 돌아가거나 이전 화면을 닫을 때 사용
Navigator.of(context).pop(result)

5) popUntil

  • 특정 조건을 만족할 때까지 화면을 스택에서 제거한다
  • 사용자가 일부 조건을 충족하는 화면으로 돌아갈 수 있도록 도움을 준다
Navigator.of(context).popUntil((route) => condition)