buttonhandler 0.0.2 copy "buttonhandler: ^0.0.2" to clipboard
buttonhandler: ^0.0.2 copied to clipboard

This package helps handle physical or hardware buttons including and not limited to volume and power buttons

buttonhandler #

This is a sample app with a plugin that handles physical(hardware) button presses. It handles the key presses using intent. From the Logcat, get the name of the intent and use it to handle the functionality of the button. For buttons that are not the usual volume or power button, we handle it using the long key presses because that is the only way we can get the intent for now.

Instanciate it like so PhysicalButtonsHandler.listen(handleKey); inside an initState

then once the hardware button is pressed, th eLogcat prints the intent which looks like so android.media.VOLUME_CHANGED_ACTION

give it a functionality like so:

void handleKey(var key) {
    print(key);
    setState(() {
      switch (key) {
        case "android.media.VOLUME_CHANGED_ACTION":
          onLongPress = true;
          showDialog(
              context: context,
              builder: (context) {
                return const AlertDialog(
                  icon: Icon(Icons.ice_skating),
                );
              });

          break;
      }
    });
  }
1
likes
0
pub points
51%
popularity

Publisher

unverified uploader

This package helps handle physical or hardware buttons including and not limited to volume and power buttons

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on buttonhandler