KeyboardDismiss class
Wrap your widget tree with a KeyboardDismiss so that:
- In iOS, if iOS is true (the default), the keyboard will follow iOS's default behavior:
- Keyboard closes when the user taps an empty area of the screen.
- Keyboard closes when the user swipes down from just above the keyboard edge.
- Any focused element will lose focus.
- In Android, the default behavior is that the keyboard only closes when the user taps the back button or executes the back gesture. However, if you want, you can force the Android to follow some iOS behaviors:
- Pass androidCloseWhenTap true, if you want the keyboard to close when the user taps an empty area of the screen.
- Pass androidCloseWhenSwipe true, if you want the keyboard to close when the user swipes down from just above the keyboard edge.
- Pass androidLoseFocus true, if you want any focused element will lose focus.
Placement
The KeyboardDismiss must be put in a place where it has the same size of the screen.
For example, if you use a Scaffold, the KeyboardDismiss should be above the scaffold, and not inside the scaffold's body.
A good place to put the KeyboardDismiss widget is in the MaterialApp.builder method. For example:
MaterialApp(
builder: (BuildContext context, Widget? child) => KeyboardDismiss(child: child);
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- KeyboardDismiss
Constructors
Properties
- androidCloseWhenSwipe → bool
-
final
- androidCloseWhenTap → bool
-
final
- androidLoseFocus → bool
-
final
- child → Widget
-
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- iOS → bool
-
final
- 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
-
swipingDownJustAboveKeyboard(
BuildContext context, Widget content) → Listener -
tappingAnywhere(
BuildContext context, Widget content) → GestureDetector -
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}) → 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
Static Methods
-
keyboardDismiss(
BuildContext context, {bool ifRemovesFocus = true}) → void -
Closes the keyboard.
If
ifRemovesFocus
is true (the default) it also removes focus from whatever widget has it.