Skip to content

TapRegion will fire callback on other navigation's stack #153093

@vfiruz97

Description

@vfiruz97

Issue's explanation is that.
if we have TapRegion on our PageA and then we push to other PageB then we continue getting callback on TapRegion's onTapOutside when we make any contact with device's screen on PageB.

Steps to reproduce

  1. just run the following code
  2. open the terminal
  3. see the print from the onTapOutside of TapRegion of both Pages in the terminal

Expected results

EditPageElement not leak

we have to not see the print from one of the TapRegion callbacks because they are in different Pages.
when we open first page we click outside the red container we see the print from the onTapOutside of TapRegion. And ther we click onto FloatingActionButton to navigate to other page. There we have another TapRegion which works the same. And here we see the terminal that we are getting callback twice. One from the first page since that has to be disposed.

Actual results

EditPageElement leaked

Code sample

Code sample
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: MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('Home'),
      ),
      body: Center(
        child: TapRegion(
          onTapOutside: (event) {
            print('From The First Page: $event');
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.red,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          Navigator.push(context, MaterialPageRoute(builder: (context) => const EditPage()));
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}

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

  @override
  StatelessElement createElement() => EditPageElement(this);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('EditPage')),
      body: Center(
        child: TapRegion(
          onTapOutside: (event) {
            print('From The Second Page: $event');
          },
          child: Container(
            width: 100,
            height: 100,
            color: Colors.red,
          ),
        ),
      ),
    );
  }
}

class EditPageElement extends StatelessElement {
  EditPageElement(super.widget);
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
From The First Page: _TransformedPointerDownEvent#92e5a(position: Offset(351.2, 276.2))
From The Second Page: _TransformedPointerDownEvent#83e76(position: Offset(136.1, 173.5))
From The First Page: _TransformedPointerDownEvent#fd16b(position: Offset(134.3, 188.6))
From The Second Page: _TransformedPointerDownEvent#fd16b(position: Offset(134.3, 188.6))
From The First Page: _TransformedPointerDownEvent#5df0f(position: Offset(16.1, 22.0))
From The Second Page: _TransformedPointerDownEvent#5df0f(position: Offset(16.1, 22.0))

Flutter Doctor output

Doctor output
~ flutter doctor                   

┌─────────────────────────────────────────────────────────┐
│ A new version of Flutter is available!                  │
│                                                         │
│ To update to the latest version, run "flutter upgrade". │
└─────────────────────────────────────────────────────────┘
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.0, on macOS 13.2.1 22D68 darwin-x64, locale
    en-TJ)
[✓] Android toolchain - develop for Android devices (Android SDK version
    34.0.0-rc2)
[!] Xcode - develop for iOS and macOS (Xcode 14.2)
    ! Flutter recommends a minimum Xcode version of 15.
      Download the latest version or update via the Mac App Store.
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.92.0)
[!] Connected device
    ! No devices available
[✓] Network resources```

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listf: gesturesflutter/packages/flutter/gestures repository.found in release: 3.24Found to occur in 3.24frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions