Giter Site home page Giter Site logo

autokaka / android_dpad_detector Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 75 KB

Widgets to help you adapt your Flutter apps for Android TV more easily.

Home Page: https://github.com/Autokaka/android_dpad_detector

License: BSD 3-Clause "New" or "Revised" License

Kotlin 1.72% Swift 5.61% Objective-C 0.53% Dart 92.14%
flutter dart android android-tv tv dpad

android_dpad_detector's Introduction

android_dpad_detector

A widget to respond to Android DPad key event. Note that this widget is only for Android TV apps, it only helps solve some annoying problems when adapting your apps for Andoird TV platform.

How to use it?

Simple enough. Just wrap a whatever widget you want with AndroidDPadDetector. For example, I want to make a TextButton respond to DPad Select event, I could write like this:

DPadDetector(
  onTap: () {
    /// On Android TV, this will respond when DPad "Select" button is pressed.
    /// On Android mobile phones, this will be the equal to `onTap` event.
  },
  onMenuTap: () {
    /// On Android TV, this will respond when DPad "MenuContext" button is pressed.
    /// On Android mobile phones, this will be equal to `onLongTap` event.
  },
  child: TextButton(...),
)

When there are complex focusable widgets in your page, for example: TextFormField, the normal FocusGroup will be behave abnormally. In that situation, you could use DPadFocusGroup. DPadFocusGroup helps you manage your FocusNodes in a List order you have just passed to this Widget. For example, if you want to manage the FocusNodes in your specified order in a group of child widgets including TextFormField, you could code like this:

List<FocusNode> focusNodeList = [
  FocusNode(),
  FocusNode(),
  FocusNode(),
];

/// ignored code...

DPadFocusGroup(
	focusNodeList: focusNodeList,
  children: [
    /// ①
    TextFormField(
    	focusNode: focusNodeList[0],
    ),
    /// ②
    DPadDetector(
      focusNode: focusNodeList[1],
      child: Text("text"),
    ),
    /// ③
    TextFormField(
    	focusNode: focusNodeList[2],
    ),
  ],
);

If you code like that, when you press →, ↓ on your DPad continually, your FocusNode will change like this: ①→②→③→①...

When you press ←, ↑ on your DPad continually, your FocusNode will change like this: ①→③→②→①...

android_dpad_detector's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

awecode

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.