I created one screen DashBoard
, in that I set bottom navigation and set other screen that all working but i need to add functionality, when user press back button than if other tab selected then it navigates to first tab other wise open Alert Dialog for asking question like "Are you sure you want to exit the app?".
I have implement using Will Pop scope set in Dash board screen.This is my code.
class DashBoardView extends GetWidget<DashBoardController> {
const DashBoardView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
MySize().init(context);
getStatusBarColor(color: AppColor.whiteF9F9F9);
return WillPopScope(
child: Scaffold(
body: Obx(() => controller.pages[controller.currentIndex.value]),
bottomNavigationBar: customBottomNavigation(),
),
onWillPop: () {
if (controller.currentIndex.value == 0) {
AppDialog.appAlertDialog(
context: context,
description: "Are you sure you want to exitnfrom the app? ",
question: 'Exit app',
questionTextStyle: TextStyle(fontSize: 14, color: AppColor.grey, fontWeight: FontWeight.w700),
onTap: () {
Get.put(SocketController()).disconnectFromSocket();
exit(0);
});
} else {
controller.currentIndex.value = 0;
controller.update();
}
return Future.value(false);
});
}
}
But it is not working in Android 14+ version, I have also replace the Will pop scope to PopScope as per latest Update but it still not working.
If Anyone face this issue so please give me suggestion about this functionality in android 14+ version.
2
Answers
Try this-
WillPopScope is deprecrated, so it is better to use PopScope.