본문 바로가기
카테고리 없음

flutter | 뒤로가기 두 번 클릭 시 앱 종료 구현

by 신도리아 2021. 11. 26.

https://stackoverflow.com/questions/53496161/how-to-write-a-double-back-button-pressed-to-exit-app-using-flutter

 

How to write a double back button pressed to exit app using flutter

I'm new to flutter, and I saw many android apps can exit when double press back button. The first time press back button, app shows a toast"press again to exit app". The following second press, app

stackoverflow.com

위의 stackoverflow 답변(Andrey Turkovsky)을 참고하여 작성하였다.

 

클래스 상단에 DateTime? currentBackPressTime; 선언해주고,

 

나 같은 경우에는 fluttertoast 대신, 

내장함수인 showSnackBar를 사용하였다.

 

알맞게 코드 변형 후, 디버깅 결과 종료 됨.