Is it possible to invoke a back button click programmatically?

Issue

I’ve seen plenty of answers explaining how to override and add functionality to a back button press via user’s interaction, but almost none of the answers explain how to programmatically trigger a back button press without any user input. Answers that do address it give somewhat deprecated code samples that don’t really compute.

Solution

From your activity just call => onBackPressed(),

or form your fragment => activity?.onBackPressed()

Answered By – Mahmoud Gamal El-Din

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *