Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to finish current view / activity in flutter?

Tags:

flutter

Is there any method similar to this.finish() in android to finish current flutter activity.

like image 222
Aman gautam Avatar asked May 24 '18 15:05

Aman gautam


People also ask

How do you exit screen in flutter?

pop() to exit the application.

How do you use pushAndRemoveUntil?

Push the given route onto the navigator that most tightly encloses the given context, and then remove all the previous routes until the predicate returns true. The predicate may be applied to the same route more than once if Route.


1 Answers

Do you mean close current screen and come back to previous screen? If that, Navigator.pop(context) should do the work. However, if you are at the entry screen (the first screen of the app and this screen has no parent screen/previous screen), Navigator.pop(context) will return you to a black screen. In this case, we have to use SystemNavigator.pop().

But don't use SystemNavigator.pop() for iOS, Apple says that the application should not exit itself :)

Below code will work on Android for both cases

if (Navigator.canPop(context)) {   Navigator.pop(context); } else {   SystemNavigator.pop(); } 
like image 108
Phuc Tran Avatar answered Oct 02 '22 20:10

Phuc Tran