우리는 앱을 개발하면서 안드로이드나 ios 에서 뒤로가기나 메인에서 앱을 종료할때 체크를 할때 기존에는
WillPopScope를 사용을 했었는데요.
이번에 Flutter 가 업데이트가 되면서 deprecated 가 되어서 다시 적용한 방법 공유해드립니다.
https://api.flutter.dev/flutter/widgets/PopScope-class.html
PopScope class - widgets library - Dart API
Manages system back gestures. The canPop parameter can be used to disable system back gestures. Defaults to true, meaning that back gestures happen as usual. The onPopInvoked parameter reports when system back gestures occur, regardless of whether or not t
api.flutter.dev
PopScope(
canPop: false,
onPopInvoked:(canPop) async {
var currentUrl = await webViewController!.getUrl();
print(currentUrl);
if (currentUrl != null) {
if (currentUrl.toString() == '해당 메인주소' || currentUrl.toString() == '해당 메인주소 및 체크해야할 주소') {
var isDoubleClicked = await onWillPopDoubleClickExit();
if (isDoubleClicked) {
if (Platform.isIOS) {
exit(0);
} else {
SystemNavigator.pop();
}
}
} else {
if (await webViewController!.canGoBack()) {
webViewController!.goBack();
}
}
}
}
위의 예제를 보시면 메인에서 PopScope를 이용해서 사용하는 방법입니다.
IOS => exit(0)
Android => SystemNavigator.pop()를 사용하시면 App 이 정상적으로 종료가 됩니다.
오늘도 즐거운 Fluttering 되세요
[Flutter] Container Radius 넣는 방법 (0) | 2024.04.02 |
---|---|
[Flutter] Flutter Local Notification 활용기 (Android HTML Format notification) (0) | 2024.02.07 |
Error (Xcode): Sandbox: rsync(13885) deny(1) (0) | 2023.12.19 |
[Flutter] Gap 에 대해 좋은 유튜브 소개 (1) | 2023.11.13 |
[GetX] GetBuilder VS Obx (0) | 2023.11.09 |