keyboard_dismisser 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

keyboard_dismisser #

A simple Flutter package to hide the keyboard when performing a gesture outside of it.

Example

Features #

  • By default, dismisses the keyboard when tapping outside of it on an inactive widget.
  • Supports several gestures at the same time.
  • Supports all the gestures available in Flutter's GestureDetector.
  • Supports directional swipes to dismiss the keyboard.
  • Can be applied to a whole page by wrapping its Scaffold.
  • Can be applied to a whole app, by wrapping its MaterialApp, WidgetsApp, or CupertinoApp.
  • Customizable drag start behavior and gesture hit testing behavior.
  • Can be excluded from the semantics tree.

Usage #

This package exposes a KeyboardDismisser stateless widget. You can wrap your widget with it, and your widget will be able to dismiss the keyboard when performing a gesture.

    Widget build(BuildContext context) => KeyboardDismisser(
        child: Scaffold(
            body: ...,
        ),
      );

KeyboardDismisser takes a gestures parameter, which is a list of GestureType enum cases. This way, you can pass any gesture you like for the keyboard dismissal. By default, KeyboardDismisser will dismiss the keyboard when tapping outside of it, but it handles several gestures at the same time.

    Widget build(BuildContext context) => KeyboardDismisser(
        gestures: [GestureType.onTap, GestureType.onPanUpdateDownDirection],
        child: Scaffold(
            body: ...,
        ),
      );

Getting started #

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  keyboard_dismisser: "^1.0.0"

Then run $ flutter pub get. In your library, add the following import:

import 'package:keyboard_dismisser/keyboard_dismisser.dart';

Author #

Diego Rogel - GitHub

Changelog #

Check the Changelog page to see what's recently changed.

License #

This project is licensed under the MIT License - see the LICENSE.md file for details.

[1.0.0] - February 2020 #

  • Initial Open Source release.

example/lib/main.dart

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

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

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
        title: 'Keyboard Dismisser',
        theme: ThemeData(primarySwatch: Colors.blue),
        home: ExamplePage(),
      );
}

class ExamplePage extends StatelessWidget {
  ExamplePage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) => KeyboardDismisser(
        gestures: [
          GestureType.onTap,
          GestureType.onPanUpdateDownDirection,
        ],
        child: Scaffold(
          appBar: AppBar(
            title: Text('KeyboardDismisser example'),
          ),
          body: Padding(
            padding: const EdgeInsets.symmetric(
              horizontal: 24,
              vertical: 48,
            ),
            child: TextField(
              decoration: InputDecoration(
                border: OutlineInputBorder(),
                labelText: 'Tap to show the keyboard',
                hintText: 'Tap elsewhere or swipe down to dismiss',
              ),
            ),
          ),
        ),
      );
}

Use this package as a library

1. Depend on it

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


dependencies:
  keyboard_dismisser: ^1.0.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_dismisser/keyboard_dismisser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
74
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]
87
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

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