1

I have a problem with closing the app from home screen.

This is my home screen code for close the app`

Future<bool> onWillPop() {
    return showDialog(
    context: context,
    builder: (BuildContext context){
      return AlertDialog(
        title: Text("Are you sure"),
        content: Text("kamu mau keluar?"),
        actions: <Widget>[
          FlatButton(
            child: Text("NO"),
            onPressed: (){Navigator.of(context).pop(false);},
          ),
          FlatButton(
            child: Text("YES"),
            onPressed: (){Navigator.of(context).pop(true);},
          ),

        ],
      );
    }
    );
  }`

but it go to login screen, not exit the app. Can someone help me? Please.

Sunny Aguilar
  • 67
  • 2
  • 6
Adam Theory
  • 103
  • 3
  • 12

1 Answers1

1

Programmatically exit the app
For Android use

SystemNavigator.pop()

SystemNavigator.pop(): Works and is the RECOMMENDED way of exiting the app.

For iOS use

exit(0)

exit(0): Works but Apple may SUSPEND YOUR APP because it's against Apple Human Interface guidelines to exit the app programmatically.

Source

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
chunhunghan
  • 51,087
  • 5
  • 102
  • 120
  • Glad to help. please mark this answer if it help your. thanks. – chunhunghan Oct 02 '19 at 01:48
  • You should also upvote other post before using them in your answer. – CopsOnRoad Oct 02 '19 at 08:42
  • They are all correct. I do not know which one to pick – chunhunghan Oct 02 '19 at 08:45
  • You don't need to pick one (you're not OP who has once choice to mark an answer accepted) if you find all of them useful, you should upvote all, you have hardly upvoted 5 upvotes in your 6.5 years SO career, develop some Stackoverflow spirit. – CopsOnRoad Oct 02 '19 at 08:46
  • I delete my account once, and active from last year and I do not know I can up vote every answer. I thought each question can get get only one up or down vote for a single person. – chunhunghan Oct 02 '19 at 08:49
  • OK, I understand, but as a user you can vote 30 post/day and there is no restriction like that. You can upvote each and every answer of a post. – CopsOnRoad Oct 02 '19 at 08:50