본문 바로가기
프로그래밍/Flutter-Dart

[Flutter] Navigator.pop 데이터 전달하기

by 채연2 2022. 3. 10.

생각보다 간단하다!

우선 A 페이지에서의 버튼을 구현해보자


		
//A
bool _state = false;
ElevatedButton(
onPressed: () async {
bool state = await Navigator.push(context,
MaterialPageRoute(builder: (context) => B()));
setState(() {
_state = state;
});
},
...
)

여기서 중요한건 async와 await 이다!

 

 

 

B 페이지에서는 다음과 같이 구현하면 된다.


		
ElevatedButton(
onPressed: () {
...
Navigator.pop(context, true);
},
...
)

 

320x100

댓글