mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fixes [CupertinoContextMenu potential unremoved overlay entry](https://github.com/flutter/flutter/issues/131471) Fixes [CupertinoContextMenu onTap gesture interferes with child widget with onTap GestureRecognizer](https://github.com/flutter/flutter/issues/169911) <details> <summary>Sample code</summary> ```dart import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; bool ctxMenuRemoved = false; class ContextMenuApp extends StatelessWidget { const ContextMenuApp({super.key}); @override Widget build(BuildContext context) { final colorScheme = ColorScheme.fromSeed(seedColor: Colors.orange); return MaterialApp( theme: ThemeData( colorScheme: colorScheme, appBarTheme: AppBarTheme(backgroundColor: colorScheme.secondaryContainer), ), home: const HomePage(), ); } } class HomePage extends StatelessWidget { const HomePage({super.key}); @override Widget build(BuildContext context) => Scaffold( appBar: AppBar( title: Text('Home'), ), body: Center( child: CupertinoContextMenu( actions: [ CupertinoContextMenuAction( child: Text('Test'), ), ], child: GestureDetector( onTap: () { Navigator.of(context).push( MaterialPageRoute(builder: (context) => _OtherPage()), ); }, child: Container( color: Colors.orange, height: 100, width: 100, ), ), ), ), ); } class _OtherPage extends StatelessWidget { const _OtherPage({super.key}); @override Widget build(BuildContext context) { return Scaffold( body: Align( child: Builder(builder: (context) { return Listener( onPointerDown: (_) { Timer(const Duration(milliseconds: 480), () { ctxMenuRemoved = true; (context as Element).markNeedsBuild(); }); }, child: ctxMenuRemoved ? const SizedBox() : CupertinoContextMenu( actions: [ CupertinoContextMenuAction( child: const Text('Action one'), onPressed: () {}, ), ], child: Container( height: 100, width: 100, color: Colors.black45, ), ), ); }), ), ); } } ``` </details>