focusnode_widgets 0.0.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

focusnode_widgets #

Reusable focus node widgets. Can be controlled with keyboard or Remote Control (e.g. on Android TV).

Usage #

To use this plugin, add focusnode_widgets as a dependency in your pubspec.yaml file.

Example #

import 'package:flutter/material.dart';
import 'package:focusnode_widgets/focusnode_widgets.dart';

void main() => runApp(MenuForAndroidTV());

class MenuForAndroidTV extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MenuForAndroidTV();
  }
}

class _MenuForAndroidTV extends State<MenuForAndroidTV> {
  final String _title = 'focusnode_widgets example for Android TV';
  final String _instructions =
      'Use DPAD up down arrow keyss to navigate and DPAD center key to open the URL';

  bool checked = false;

  @override
  Widget build(BuildContext context) {
    final TextTheme textTheme = Theme.of(context).textTheme;

    void launchUrl(BuildContext context) {
      // put code to launch the URL here
      // on android TV url needs to be launched in WebView as per guidelines,
      // browser can't be used
    }

    HyperLinkMenuItem flutterLink = HyperLinkMenuItem(
      displayText: 'Flutter - Beautiful native apps in record time',
      launchUrl: launchUrl,
      autoFocus: true,
    );

    void _onChanged(BuildContext context, bool selected) {
      checked = selected;
      setState(() {});
    }

    CheckboxListTileMenuItem checkboxListTileMenuItem =
        CheckboxListTileMenuItem(
      title: DefaultTextStyle(
          style: textTheme.headline,
          child: Text('I accept Terms and Conditions')),
      enterTapActionCallback: _onChanged,
      value: checked,
      controlAffinity: ListTileControlAffinity.leading,
    );

    Text nonFocusableText2 = Text('Non focusable text item 2');

    void _handleEnterTapAction(BuildContext context) {
      final snackBar = SnackBar(
        content: Text('Yay! A SnackBar!'),
        action: SnackBarAction(
          label: 'Undo',
          onPressed: () {
            // Some code to undo the change.
          },
        ),
      );
      Scaffold.of(context).showSnackBar(snackBar);
    }

    FocusableSimpleMenuItem focusableSimpleMenuItem = FocusableSimpleMenuItem(
      child: Text('Click, Tap or Press Enter/ OK to show SnackBar'),
      enterTapActionCallback: _handleEnterTapAction,
    );

    Text instructions = Text(_instructions);

    VerticalMenuForAndroidTV verticalMenuForAndroidTV =
        VerticalMenuForAndroidTV(
      menuItems: [
//        keyPrintMenuItem,
//        keyLogShort,
        flutterLink,
        nonFocusableText2,
        checkboxListTileMenuItem,
        focusableSimpleMenuItem,
        instructions,
      ],
      focusedBackgroundDecoration: BoxDecoration(
        border: Border.all(color: Colors.amber[900], width: 2),
      ),
      alignment: Alignment.center,
      constraints: BoxConstraints(
        maxHeight: 40,
        maxWidth: 700,
        minHeight: 10,
        minWidth: 100,
      ),
    );

    DefaultTextStyle menu = DefaultTextStyle(
      style: textTheme.headline,
      child: verticalMenuForAndroidTV,
    );

    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: Text(_title)),
        body: menu,
      ),
    );
  }
}

[0.0.9] - 4 Sep 2019

  • Modified HyperLinkMenuItem to not to call the launchUrl internally, provided callback for the same, on android TV url needs to be launched in WebView as per guidelines,

[0.0.8] - 2 Sep 2019

  • Bug fix : D-PAD - center (logical select key was not handled)

[0.0.7] - 2 Sep 2019

  • Support of KeyPrintMenuItem

[0.0.6] - 1 Sep 2019

  • It should be possible to accept any Widget in VerticalMenuForAndroidTV

[0.0.5] - 1 Sep 2019

  • Support of CheckboxListTileMenuItem

[0.0.4] - 1 Sep 2019

  • Support of adding any StatelessWidget to VerticalMenu, It won't receive focus.

  • VerticalMenuForAndroidTV now accepts list of StatelessWidget as menu items

  • Support of FocusableSimpleMenuItem which can be added to VerticalMenuForAndroidTV

  • Support of adding any widget to VerticalMenuForAndroidTV, it won't get focused

  • Added example code in README.md

[0.0.3] - 1 Sep 2019

  • Bug fix, VerticalMenuItem needs to extend from StatelessWidget

[0.0.2] - 31 Aug 2019

  • VerticalMenuForAndroidTV and HyperLinkMenuItem supported,

  • Container parameters are passed to VerticalMenuForAndroidTV which are used to display the MenuItem

  • Example updated

[0.0.1] - 31 Aug 2019

  • Initial Open Source release.

example/README.md

example #

focusnode_widgets package example

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  focusnode_widgets: ^0.0.9

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:focusnode_widgets/focusnode_widgets.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
58
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Oct 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test