HIT해
[Flutter] 팝업 외부 클릭시에도 네비게이터 작동하는 방법 본문
728x90
팝업 내부의 버튼을 누르지 않고 외부를 눌렀을때 팝업이 꺼지면서 네비게이터 이동을 하는 방법은 간단하다.
showDialog의 barrierDismissible을 true로 바꿔주고
WillPopScope 위젯은 사용해 팝업창이 닫힐 때(pop이 발생할 때) LoginScreen으로 이동하게한다.
onWillPop을 팝업창이 닫히려고 할때 호출되는 함수다.
아래에 예시 코드가 있다.
void corretDialog(context) {
showDialog(
context: context,
barrierDismissible: true,
builder: (context) {
return WillPopScope(
onWillPop: () async {
Navigator.push(context,
MaterialPageRoute(builder: (context) => LoginScreen()));
return true;
},
child: Dialog(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("임시비밀번호 발급 성공"),
IconButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => LoginScreen()));
},
icon: const Icon(Icons.close),
)
],
),
),
);
},
);
}
'Flutter > Flutter 개발 노트' 카테고리의 다른 글
[Flutter] Provider이해와 사용법 / 무한 렌더링 해결하기! (0) | 2024.02.09 |
---|---|
[Flutter] 카카오 로그인 구현하기 ③ ( 서버 설정 ) (0) | 2024.02.09 |
[Flutter] 한글깨짐 json.decode 해결방법 (0) | 2024.02.02 |
[Flutter] 카카오 로그인 구현하기 ② ( Flutter 설정 ) (0) | 2024.01.31 |
[Flutter] 카카오 로그인 구현하기 ① ( 환경설정 ) (0) | 2024.01.31 |