How can I make parent widget's onTap and child widget's onTap to be called together?
I have a page which consist of several widgets which has their own onTap. One of the component is a TextField and when it is tapped, keyboard is opened. I want to close that keyboard when user taps outside of this TextField. But the child widget's onTap is triggered and parent's onTap is not.
When child onTap wins and opens a new page, if you navigate back, keyboard is opened again. How can I solve this issue?
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: ParentClicky(),
);
}
}
class ParentClicky extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: GestureDetector(
onTap: () => print('PARENT CLICKED'),
child: Container(
width: double.infinity,
height: double.infinity,
color: Colors.pink,
child: Center(child: ChildClicky()),
),
),
);
}
}
class ChildClicky extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => print('CHILD CLICKED'),
child: Container(
width: 100,
height: 100,
color: Colors.yellow,
),
);
}
}