import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:regroup/Common/controller/MainController.dart'; import 'package:regroup/Main_Screens/ProfileTab/EditProfile/ViewModel/InterestApiList.dart'; final MainController mainController = Get.put(MainController()); class MainScreen extends StatefulWidget { const MainScreen({super.key}); @override State createState() => _MainScreenState(); } class _MainScreenState extends State { @override void initState() { InterestListApi().getinterestlistApi(); super.initState(); } @override Widget build(BuildContext context) { return Obx(() { return WillPopScope( onWillPop: () async { _onBackButtonPressed(context); return true; // Return true to allow the pop action }, child: Scaffold( resizeToAvoidBottomInset: false, body: mainController.currentTab[mainController.selectedIndex.value], ), ); }); } Future _onBackButtonPressed(BuildContext context) async { bool? exitApp = await showDialog( context: context, builder: (context) { return AlertDialog( backgroundColor: Color(0xFF222935), title: const Text('Exit App', style: TextStyle(color: Colors.white)), content: const Text('Do you really want to close the app?', style: TextStyle(color: Colors.white)), actions: [ TextButton( onPressed: () { Navigator.of(context).pop(false); }, child: const Text( 'No', style: TextStyle( color: Color(0xFFD90B2E), ), ), ), TextButton( onPressed: () { SystemNavigator.pop(); Navigator.pop(context); }, child: const Text( 'Yes', style: TextStyle( color: Color(0xFFD90B2E), ), ), ) ], ); }, ); return exitApp ?? false; } }