1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter: How can I prevent default behaviour on key press?

Discussão em 'Mobile' iniciado por Stack, Setembro 21, 2021.

  1. Stack

    Stack Membro Participativo

    I'm trying to intercept when a user presses the volume buttons to perform a specific action and prevent the default behaviour (volume changes).

    This is the code I have so far:

    RawKeyboard.instance.addListener(_keyboardListener);

    void _keyboardListener(RawKeyEvent e) {
    if(e.runtimeType == RawKeyUpEvent) {
    RawKeyEventDataAndroid eA = e.data;
    if(eA.keyCode == 24) { //volume up key
    _goNextPage();
    }
    if(eA.keyCode == 25) { //volume down key
    _goPrevPage();
    }
    }
    }


    How would I go about preventing the volume from changing (and stopping the volume slider from appearing at the top)?

    A Javascript analogous would be calling event.preventDefault() on the key event.

    This seems to be a rather trivial matter, but I haven't been able to find any answers in the docs.

    Thanks.

    Continue reading...

Compartilhe esta Página