Is there any method similar to this.finish()
in android to finish current flutter activity.
pop() to exit the application.
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.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With