KeyboardDismiss class

A widget that can dismiss the keyboard when performing a gesture.

Wrapping any widget with this widget will trigger the keyboard's dismissal when performing a gesture in an area of the screen with no other widgets that can absorb the gesture in it. For example, if a KeyboardDismiss that is looking to dismiss the keyboard when performing a gesture of GestureType.onTap is wrapping a widget that contains a button, the keyboard will be dismissed when tapping outside of the button, but it won't when tapped inside it, since the button will be pushed, absorbing the tap.

Typical usage of KeyboardDismiss involves wrapping a whole page with it, including its Scaffold, so that the keyboard is dismissed when tapping on any inactive widget. For example:

class KeyboardDismissiblePageWithButton extends StatelessWidget {
 @override
 Widget build(BuildContext context) => KeyboardDismisser(
       child: Scaffold(
         appBar: AppBar(
           title: Text('KeyboardDismisser example'),
         ),
         body: Column(
           children: <Widget>[
             Padding(
               padding: const EdgeInsets.all(42.0),
               child: TextField(
                 decoration: InputDecoration(
                   border: OutlineInputBorder(),
                   labelText: 'Tap to show the keyboard',
                   hintText: 'Tap elsewhere to dismiss',
                 ),
               ),
             ),
             Center(
               child: RaisedButton(
                 onPressed: () => print('Keyboard persists'),
                 child: Text('Tap me!'),
               ),
             ),
           ],
         ),
       ),
     );
}

Wrapping a MaterialApp, WidgetsApp or CupertinoApp with a KeyboardDismiss will make the whole app acquire the behaviour from KeyboardDismiss, since every Scaffold will be a child of the corresponding app widget.

Inheritance

Constructors

KeyboardDismiss({Key? key, Widget? child, HitTestBehavior? behavior, List<GestureType> gestures = const [GestureType.onTap], DragStartBehavior dragStartBehavior = DragStartBehavior.start, bool excludeFromSemantics = false})
Creates a widget that can dismiss the keyboard when performing a gesture.
const

Properties

behavior HitTestBehavior?
How the this widget's GestureDetector should behave when hit testing.
final
child Widget?
The widget below this widget in the tree.
final
dragStartBehavior DragStartBehavior
Determines the way that drag start behavior is handled.
final
excludeFromSemantics bool
Whether to exclude these gestures from the semantics tree.
final
gestures List<GestureType>
The list of gestures that will dismiss the keyboard when performed.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited