KeyboardDismisser class
A custom Flutter widget that automatically dismisses the on-screen keyboard when the user taps outside of an input field. This is especially useful in forms or other text input scenarios where the keyboard may obscure important parts of the UI, and the user needs a convenient way to close it.
Features:
- Automatic Keyboard Dismissal: Taps outside of input fields will unfocus the current text input, effectively closing the keyboard.
- Smart Detection: The widget intelligently checks if the tap occurred outside the currently focused input field and dismisses the keyboard only when appropriate.
- Seamless Integration: Wrap this widget around any part of your UI where you want this behavior, and it will work in harmony with your existing components.
Usage:
To use KeyboardDismisser
, simply wrap it around the part of your widget tree
where you want the keyboard to be dismissed on an outside tap:
KeyboardDismisser(
child: YourWidget(),
)
This widget is particularly useful in scenarios where you want to improve user experience by automatically dismissing the keyboard when the user is done typing or interacts with other parts of the UI.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- KeyboardDismisser
Constructors
- KeyboardDismisser.new({Key? key, required Widget child, bool stopDismiss(HitTestTarget target) = _stopDismiss})
-
const
Properties
- child → Widget
-
The widget that contains the keyboard.
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
- stopDismiss → bool Function(HitTestTarget target)
-
Whether stop dismiss keyboard.
final
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