Coder Social home page Coder Social logo

drogel / keyboard_dismisser Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 11.0 1.5 MB

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

License: MIT License

Dart 91.97% Kotlin 0.58% Swift 1.92% Objective-C 0.18% HTML 5.35%

keyboard_dismisser's Introduction

keyboard_dismisser

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

Pub

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: "^[LATEST_VERSION]"

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 file for details.

keyboard_dismisser's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

keyboard_dismisser's Issues

flutter 3.0.0 detecting issue in the library

/D:/flutter_windows_3.0.0-stable/flutter/.pub-cache/hosted/pub.dartlang.org/keyboard_dismisser-2.0.1/lib/keyboard_dismisser.dart(418,22): warning G1E0FE241: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null. [D:\FlutterProjects\billz_cashier_desktop\build\windows\flutter\flutter_assemble.vcxproj]

Ability to disable dismissal on certain widgets

Hi and thank you for the package !
I'm trying to achieve the facebook messenger app kind of UX on my chat app, the issue in hand is that I want to keep the keyboard shown when user taps on the send message widget but at the same time I'm using the Keyboard dismiss globally in my materialApp builder , I couldn't find a trick to disabling the dismissal on a specific widget, do you think it's possible to have a widget 'preventKeyboardDismissal' wrapping the send message button to achieve the desired behavior ?

On Hide Keyboard Function

How to know when the keyboard is hidden?
I think this plugin needs an onHideKeyboard function.
Will you update this?

Error: Property 'focusManager' cannot be accessed on 'WidgetsBinding?' because it is potentially null.

`/D:/flutter/.pub-cache/hosted/pub.dartlang.org/keyboard_dismisser-3.0.0/lib/keyboard_dismisser.dart:418:31: Error: Property 'focusManager' cannot be accessed on 'WidgetsBinding?' because it is potentially null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/D:/flutter/packages/flutter/lib/src/widgets/binding.dart').
    Try accessing using ?. instead.
    WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();`
    image

on keyboard hide

this package does not work if the keyboard hide it sill fouces thanks

does not work on web mobile

it seems that this package does not work on web mobile; tapping outside of the textfield after wrapping the page in KeyboardDismisser() does not dismiss the keyboard

Add a Helper Function to Dismiss Keyboard On Callback

Sometimes I want to dismiss the keyboard because the user dragged or tapped outside of a given widget, this package is great for this!

However, in other places I also want to dismiss the keyboard from an arbitrary callback. As such, it'd be great if this package provided both. Here's one version of what this could look like:

// In `KeyboardDismisser`.
static void dismiss(BuildContext context) {...}
.
.
.
// In my arbitrary callback.
KeyboardDismisser.dismiss(context);

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.