I guess you can close the keyboard
if already open before clicking on another GestureDetector
widgets
Something like:
class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
final _textController = TextEditingController();
bool _isKeyboardOpen = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
// Close keyboard if it is open
if (_isKeyboardOpen) {
FocusScope.of(context).unfocus();
_isKeyboardOpen = false;
}
},
child: Scaffold(
appBar: AppBar(title: Text('My Widget')),
body: Column(
children: [
TextField(
controller: _textController,
onTap: () {
// Set keyboard open flag to true when text input is tapped
_isKeyboardOpen = true;
},
),
GestureDetector(
onTap: () {
// Handle tap on this widget
print('Tapped on GestureDetector');
},
child: Container(
width: 100,
height: 100,
color: Colors.blue,
child: Center(child: Text('Clickable widget')),
),
),
],
),
),
);
}
}