keyboard_overlay 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

keyboard_overlay #

A simple way to show overlay widgets when keyboard rises, without changing widget three from your current project. #

It shows a custom widget when TextFields get focused, and everything is disposed automatically on StatefulWidget dispose.

preview_1

Add dependency

dependencies:
    keyboard_overlay: ^0.1.0
//use mixin on State<StatefulWidget>: HandleFocusNodesOverlayMixin

Init FocusNodeOverlay #

@override
void initState() {
    _nodePassword = GetFocusNodeOverlay(
        child: SpecialDismissable(
            onOkButton: () => print(_nodePassword.controller.text),
            title: 'SPECIAL',
        ),
        controller: TextEditingController()
    )    
}

Use it on TextFields #

TextFormField(
    focusNode: _nodePassword,
    controller: _nodePassword.controller
)
@override
void dispose() {
    // Don't need to dispose FocusNodeOverlay and TextEditingController, it will be disposed automatically
    super.dispose();
}

[0.1.0] - Initial release #

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Keyboard Overlay Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Keyboard Overlay Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Text(
          'Go to next screen',
          style: Theme.of(context).textTheme.display1,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.of(context).push(MaterialPageRoute(
              builder: (BuildContext context) => SecondPage()));
        },
        tooltip: 'next',
        child: Icon(Icons.arrow_forward),
      ),
    );
  }
}

class SecondPage extends StatefulWidget {
  SecondPage({Key key}) : super(key: key);
  @override
  _SecondPageState createState() => _SecondPageState();
}

class _SecondPageState extends State<SecondPage>
    with HandleFocusNodesOverlayMixin {
  //Use Mixin HandleFocusNodesOverlayMixin

  FocusNodeOverlay _nodeCats;
  FocusNodeOverlay _nodeDogs;
  FocusNodeOverlay _nodePassword;

  @override
  void initState() {
    super.initState();

    _nodeCats = GetFocusNodeOverlay(
      // call method from Mixin GetFocusNodeOverlay
      child: TopKeyboardUtil(
        DoneButtonIos(
          label: 'Next',
          onSubmitted: () => _nextField(_nodeCats, _nodeDogs),
          platforms: ['android', 'ios'],
        ),
      ),
    );

    _nodeDogs = GetFocusNodeOverlay(
        child: TopKeyboardUtil(
          SliderComponent(
            controller: (double value) {
              _nodeDogs.controller.text = (value * 100).round().toString();
            },
            onSubmitted: () => _nextField(_nodeDogs, _nodePassword),
          ),
        ),
        controller: TextEditingController());

    _nodePassword = GetFocusNodeOverlay(
        child: SpecialDismissable(
          onOkButton: () => print(_nodePassword.controller.text),
          title: 'SPECIAL',
        ),
        controller: TextEditingController());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SingleChildScrollView(
          child: Column(
        children: <Widget>[
          SizedBox(height: 16),
          Padding(
            padding: const EdgeInsets.all(16),
            child: TextFormField(
              focusNode: _nodeCats, // Adicionado focus node
              textInputAction: TextInputAction.next,
              autofocus: true,
              onFieldSubmitted: (term) async {
                _nextField(_nodeCats, _nodePassword);
              },
              keyboardType: TextInputType.numberWithOptions(decimal: true),
              style: TextStyle(color: Colors.grey),
              decoration: InputDecoration(
                labelText: 'How many cats?',
                labelStyle: TextStyle(color: Colors.black),
                fillColor: Colors.orange,
                hintStyle: TextStyle(
                  color: Colors.grey,
                ),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.black, width: 1.0),
                ),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(16),
            child: TextFormField(
              focusNode: _nodeDogs, // focus node added
              controller: _nodeDogs.controller, // controller added
              textInputAction: TextInputAction.next,
              onFieldSubmitted: (term) async {
                _nextField(_nodeCats, _nodePassword);
              },
              keyboardType: TextInputType.numberWithOptions(decimal: true),
              style: TextStyle(color: Colors.grey),
              decoration: InputDecoration(
                labelText: 'How many dogs?',
                labelStyle: TextStyle(color: Colors.black),
                fillColor: Colors.orange,
                hintStyle: TextStyle(
                  color: Colors.grey,
                ),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.black, width: 1.0),
                ),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.all(16),
            child: TextFormField(
              focusNode: _nodePassword, // CustomFocusNode
              controller:
                  _nodePassword.controller, // use controller from focusNode
              textInputAction: TextInputAction.done,
              obscureText: true,
              onFieldSubmitted: (term) async {
                print(_nodePassword.controller.text);
              },
              style: TextStyle(color: Colors.grey),
              decoration: InputDecoration(
                labelText: 'Enter password',
                labelStyle: TextStyle(color: Colors.black),
                fillColor: Colors.orange,
                hintStyle: TextStyle(
                  color: Colors.grey,
                ),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.black, width: 1.0),
                ),
                suffixIcon: IconButton(
                  icon: Icon(
                    Icons.remove_red_eye,
                    color: Colors.black87,
                    size: 20,
                  ),
                  onPressed: () {},
                ),
              ),
            ),
          ),
        ],
      )),
    );
  }

  _nextField(FocusNode prev, FocusNode next) {
    prev.unfocus();
    FocusScope.of(context).requestFocus(next);
  }

  @override
  void dispose() {
    // Don't need to dispose FocusNodeOverlay and TextEditingController, it will be disposed automatically
    super.dispose();
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  keyboard_overlay: ^0.1.0

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:keyboard_overlay/keyboard_overlay.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:keyboard_overlay/keyboard_overlay.dart that imports:
  • package:keyboard_overlay/src/keyboard_overlay_manager.dart that imports:
  • package:keyboard_visibility/keyboard_visibility.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:keyboard_overlay/keyboard_overlay.dart that imports:
  • package:keyboard_overlay/src/keyboard_overlay_manager.dart that imports:
  • package:keyboard_visibility/keyboard_visibility.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:keyboard_overlay/keyboard_overlay.dart that imports:
  • package:keyboard_overlay/src/keyboard_overlay_manager.dart that imports:
  • package:keyboard_visibility/keyboard_visibility.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:keyboard_overlay/keyboard_overlay.dart that imports:
  • package:keyboard_overlay/src/keyboard_overlay_manager.dart that imports:
  • package:keyboard_visibility/keyboard_visibility.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • keyboard_overlay that is a package requiring null.

Health suggestions

Fix lib/src/handle_focus_nodes_overlay_mixin.dart. (-0.50 points)

Analysis of lib/src/handle_focus_nodes_overlay_mixin.dart reported 1 hint:

line 10 col 13: Name non-constant identifiers using lowerCamelCase.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
keyboard_visibility ^0.5.6 0.5.6
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test