0

I am using flutter for development and I want to send app to background or close it when user clicks on back icon on appbar

I have used this answer for reference but apart from exit(0) is nothing working, which is not recommended in iOS.

I have tried following recommendations from other answers but none of it working on iOS.

   Navigator.of(context).pop();
   Navigator.of(context).maybePop();
   Navigator.of(context, rootNavigator: true).pop(context);
   Navigator.pushReplacementNamed(context, '/route');
   SystemNavigator.pop();
   Navigator.pop(context,true);
   SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          

for android following is working properly.

SystemNavigator.pop();

What should I use to close the app within apple guidelines.

EDIT

SystemNavigator.pop(); gives black screen in iOS.

rookieDeveloper
  • 2,459
  • 1
  • 22
  • 44
  • 1
    That isn't how app navigation works on iOS. Users expect to stay in an app until they press the home button or swipe up on the bottom of the screen. Even though you are developing a cross-device application you should follow the conventions of each platform. iOS users will interpret suddenly returning to the springboard as an app crash. – Paulw11 Aug 25 '21 at 13:04
  • @Paulw11 Thank you, just to be sure I only need to write the `close app` part for android? – rookieDeveloper Aug 25 '21 at 13:06

1 Answers1

1

Try this

appBar: AppBar(
      leading: IconButton(
        icon: Icon(Icons.arrow_back, color: Colors.black),
        onPressed: () => Navigator.of(context).pop(),
      ), 
      title: Text("Sample"),
      centerTitle: true,
    ),