Repository: flutter
Issue: After GestureDetector deactivate, onTap event should not be triggered
Labels: framework,f: gestures,a: error message,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.19,found in release: 3.22

When `GestureDetector` is nested, `onTap` may trigger after Element `deactivate`.

### Steps to reproduce

Click on the blue area.

### Expected results

`onTap` don't trigger after Element `deactivate`.

### Actual results

`onTap` triggered after Element `deactivate`.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Listener(
        onPointerDown: (event) {
          print('onPointerDown');
          Navigator.of(context).pop();
        },
        child: GestureDetector(
          onTap: () {
            print('onTap');
            Navigator.of(context);
          },
          child: GestureDetector(
            onDoubleTap: () {
              print('onDoubleTap');
            },
            child: Container(
              width: 100,
              height: 100,
              color: Colors.blue,
            ),
          ),
        ),
      ),
    );
  }
}

```

</details>


### Logs

<details open><summary>Logs</summary>

```console
I/flutter (13046): onPointerDown
I/flutter (13046): onTap

======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

When the exception was thrown, this was the stack: 
#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:4738:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:4752:6)
#2      Element.findAncestorStateOfType (package:flutter/src/widgets/framework.dart:4823:12)
#3      Navigator.of (package:flutter/src/widgets/navigator.dart:2689:40)
#4      HomePage.build.<anonymous closure> (package:example/main.dart:30:23)
#5      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:315:24)
#6      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:652:11)
#7      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:309:5)
#8      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:279:7)
#9      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:167:27)
#10     GestureArenaManager.release (package:flutter/src/gestures/arena.dart:213:7)
#11     DoubleTapGestureRecognizer._reset (package:flutter/src/gestures/multitap.dart:320:44)
#12     DoubleTapGestureRecognizer.dispose (package:flutter/src/gestures/multitap.dart:305:5)
#13     RawGestureDetectorState.dispose (package:flutter/src/widgets/gesture_detector.dart:1481:18)
#14     StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5689:11)
#15     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2076:13)
```

</details>

### Reason

`onDoubleTap GestureDetector` is nested within `onTap GestureDetector`. when pop page,
`onDoubleTap GestureDetector` firstly dispose, then called `onTap GestureDetector` onTap. 
but `onTap GestureDetector` is deactivate, context can't be used.

so, when GestureDetector is deactivate, onTap should not be called.



### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on macOS 12.7.4 21H1123 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.6)
[✓] IntelliJ IDEA Community Edition (version 2023.2.5)
[✓] VS Code (version 1.78.2)
```

</details>