Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 229 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I dismiss the on screen keyboard?

#11
To summarize, this is a working solution for Flutter 1.17:

Wrap your Widget like this:

GestureDetector(
onTap: FocusScope.of(context).unfocus,
child: YourWidget(),
);

Reply

#12
To dismiss the keyboard (1.7.8+hotfix.2 and above) just call the method below:

FocusScope.of(context).unfocus();

Once the **FocusScope.of(context).unfocus()** method already check if there is focus before dismiss the keyboard it's not needed to check it. But in case you need it just call another context method: `FocusScope.of(context).hasPrimaryFocus`
Reply

#13
You can also declare a focusNode for you textfield and when you are done you can just call the unfocus method on that focusNode
and also dispose it

```dart
class MyHomePage extends StatefulWidget {
MyHomePageState createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
TextEditingController _controller = new TextEditingController();

/// declare focus
final FocusNode _titleFocus = FocusNode();

@override
void dispose() {
_titleFocus.dispose();
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(),
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.send),
onPressed: () {
setState(() {
// send message
// dismiss on screen keyboard here

_titleFocus.unfocus();
_controller.clear();
});
},
),
body: new Container(
alignment: FractionalOffset.center,
padding: new EdgeInsets.all(20.0),
child: new TextFormField(
controller: _controller,
focusNode: _titleFocus,
decoration: new InputDecoration(labelText: 'Example Text'),
),
),
);
}
}
```
Reply

#14
For me, the Listener above App widget is the best approach I've found:

```
Listener(
onPointerUp: (_) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
currentFocus.focusedChild.unfocus();
}
},
child: MaterialApp(
title: 'Flutter Test App',
theme: theme,
...
),
)
```
Reply

#15
This may simplify the case. Below code will work only if keyboard is open


if(FocusScope.of(context).isFirstFocus) {
FocusScope.of(context).requestFocus(new FocusNode());
}
Reply

#16
FocusScope.of(context).unfocus() has a downside when using with filtered listView.
Apart from so many details and concisely, use keyboard_dismisser package in

[To see links please register here]

will solve all the problems.
Reply

#17
if you use CustomScrollView, just put,

```
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
```
Reply

#18
You can wrap your widget with "GestureDetector", then assign "FocusScope.of(context).unfocus()" to its onTap function

GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: child,
);
Reply

#19
try using a TextEditingController.
at the begining,

final myController = TextEditingController();
@override
void dispose() {
// Clean up the controller when the widget is disposed.
myController.dispose();
super.dispose();
}


and in the on press event,

onPressed: () {
myController.clear();}
this will dismiss the keybord.


Reply

#20
I have created this function to my base code, so far works well!!

void hideKeyword(BuildContext context) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
currentFocus.focusedChild.unfocus();
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through