swipingDownJustAboveKeyboard method

Listener swipingDownJustAboveKeyboard(
  1. BuildContext context,
  2. Widget content
)

Implementation

Listener swipingDownJustAboveKeyboard(BuildContext context, Widget content) {
  return Listener(
    behavior: HitTestBehavior.translucent,
    onPointerMove: (PointerMoveEvent evt) {
      //
      double dy = evt.delta.dy;

      // If the user is swiping down.
      if (dy > 0.0) {
        //
        var fingerPosition = evt.position.dy;

        MediaQueryData data = MediaQuery.of(context);
        double height = data.size.height;
        double bottom = data.viewInsets.bottom;
        double keyboardEdgePosition = height - bottom;

        /// Close the keyboard if the keyboard is open (bottom > 0.0)
        /// and the user finger is passing through the bottom 16 pixels above the keyboard.
        if (bottom > 0.0 &&
            (fingerPosition > keyboardEdgePosition) &&
            (fingerPosition - dy <= keyboardEdgePosition)) _keyboardDismiss(context);
      }
    },
    child: content,
  );
}