Flutter: How to check if home button and power button are pressed in device

Viewed 388

How to check if the home button or the power button are pressed in an android/ios device in Flutter App.

There is a package - https://pub.dev/packages/hardware_buttons

Now it is not compatible with Flutter 2.10.

Error - "The plugin `hardware_buttons` uses a deprecated version of the Android embedding."

I tried using it, but it is showing that it is deprecated, because it was using Android V1 Embedding.

1 Answers

You do not need to catch Home button. If user press Home and some other Activity comes to foreground, your app goes to background and onPause() is called in your current Activity.override method onpause() and then do what you want.

Related