Skip to content

GestureDetector.onTap not being hit when behind GestureDetector with HitTestBehavior.translucent #92103

@kenzieschmoll

Description

@kenzieschmoll

In this example, I would expect both print statements to be hit, but only the "inside" GestureDetector's onTap is being triggered.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gesture Detector Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Gesture Detector Demo'),
      ),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () => print('outside gesture detector'),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              GestureDetector(
                onTap: () => print('inside gesture detector'),
                behavior: HitTestBehavior.translucent,
                child: Container(
                  color: Colors.green,
                  height: 100.0,
                  width: 300.0,
                  child: const Text(
                    'Gesture detector - HitTestBehavior.translucent',
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/f: gesturesflutter/packages/flutter/gestures repository.frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions