This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
An abstraction for an entry managed by a Navigator.
Navigator 에 의해 이동하게 될 앱의 화면, 페이지를 나타내는 정보들을 가지고 있다.
Navigator class 가 Route class 의 정보를 이용해서 지정된 route 로 이동하고 돌아오는 동작을 할수 있게 된다.
간단하게 Navigator 가 사용가능 한 MaterialApp class 를 이용해본다.
MaterialApp 에는 앱 에서 사용 할 모든 route 를 가진 table 를 지정해야 한다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
이름에 해당하는 route 로 이동한다. route 의 이름을 인자(routeName)로 전달한다.
실제 하는 동작은 route 이름을 Navigator 의 onGenerateRoute 콜백에 전달하여 route 를 생성한 후 Navigator 에 push 한다.
argumensts 는 이동하려는 route 로 전달할 수 있는 값이다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
routes 목록에 있는 'page1' 과 같지만 이름을 쓰지 않고 route 를 직접 전달하여 동작한다.
새로운 route 가 push 되고 이전 route 로 돌아갈때는 pop 을 한다.
Navigator.pop
bool pop <T extendsObject>(
BuildContext context, [
T result
])
context 상에서 가장 가까운 이전 route 를 찾아 이동한다.
result 는 돌아가는 route 에 전달할 수 있는 값이다.
Example of Navigator push and pop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'page1' 버튼을 누르면 MaterialPageRoute() 로 page1 route 를 생성하여 push() 한다.
Page1 에서 'Back' 버튼을 누르면 pop() 을 호출하여 이전 페이지로 돌아간다.
Return data
이전 route 로 돌아갈 때 pop() 의 result 를 통해 데이터를 전달할 수 있다.
Page2 에서 home page 로 이동하기 위해 'Back' 버튼을 누른 시간을 전달하여 home page 에 표시 해본다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
home page 에서 Page3 로 이동하는 시간을 argument 로 전달해 Page3 의 visitTime 값이 지정된다.
Page3 constructor 에 visitTime 을 추가한다.
Page3({Key key, @requiredthis.visitTime})
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Home page 에서 Page4 로 이동 시 Map object 로 'message' 와 'time' 값을 전달한여 Page4 에서 화면에 출력하는 예제이다.
argument 는 ModalRoute.of 을 이용해 얻는다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters