If the widget supports event detection, pass a function to it and
handle it in the function. For example, the ElevatedButton has an
onPressed parameter:

    
@override
Widget build(BuildContext context) {
  return ElevatedButton(
    onPressed: () {
      developer.log('click');
    },
    child: const Text('Button'),
  );
}

If the widget doesn’t support event detection, wrap the
widget in a GestureDetector and pass a function
to the onTap parameter.

    
class SampleApp extends StatelessWidget {
  const SampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: GestureDetector(
          onTap: () {
            developer.log('tap');
          },
          child: const FlutterLogo(size: 200.0),
        ),
      ),
    );
  }
}