Skip to content

Added an exit dialogue in mainwrapper.dart #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions lib/mainwrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,32 @@ class MainWrapperState extends State<MainWrapper> {
];

Future<bool> _systemBackButtonPressed() async {
if (_navigatorKeys[_selectedIndex].currentState?.canPop() == true) {
_navigatorKeys[_selectedIndex]
.currentState
?.pop(_navigatorKeys[_selectedIndex].currentContext);
return false;
} else {
SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop');
return true; // Indicate that the back action is handled
}
if (_navigatorKeys[_selectedIndex].currentState?.canPop() == true) {
_navigatorKeys[_selectedIndex]
.currentState
?.pop(_navigatorKeys[_selectedIndex].currentContext);
return false;
} else {
return await showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('Exit App'),
content: Text('Do you really want to exit the app?'),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text('No'),
),
TextButton(
onPressed: () => SystemChannels.platform.invokeMethod<void>('SystemNavigator.pop'),
child: Text('Yes'),
),
],
),
) ?? false;
}
}


@override
Widget build(BuildContext context) {
Expand Down