keyboardfocusfluttertelevision

How to let flutter apps support TV device?


TV device does not support touch operation, users have to use Remote Control. We need to move focus by press left, top, right, bottom direction key, and when the target widget get focus, we will press OK button to response kinds of key event. But I cannot find any flutter interface to solve this interaction, anyone who can help me?


Solution

  • There are SystemChannels for this. I haven't tried it myself, but it looks like this should do what you need:

    DartDocs - SystemChannels.keyEvent

    A JSON BasicMessageChannel for keyboard events.

    [DartDocs - SystemChannels.textInput[(https://www.dartdocs.org/documentation/flutter/0.0.41-dev/services/SystemChannels/textInput-constant.html)

    A JSON MethodChannel for handling text input.

    This channel exposes a system text input control for interacting with IMEs (input method editors, for example on-screen keyboards). There is one control, and at any time it can have one active transaction. Transactions are represented by an integer. New Transactions are started by TextInput.setClient. Messages that are sent are assumed to be for the current transaction (the last "client" set by TextInput.setClient). Messages received from the shell side specify the transaction to which they apply, so that stale messages referencing past transactions can be ignored.

    The later is used in https://github.com/flutter/flutter/blob/4389f07024a4c69f7223401abd4d0ab3ecc45698/packages/flutter/lib/src/services/text_input.dart

    There are known issues with physical keyboards thought that might cause this use case not to work