Skip to content

Tooltip exception: Bad state: Instance of '_OverlayEntryLocation' is already disposed #129025

@tgucio

Description

@tgucio

Is there an existing issue for this?

Steps to reproduce

Run the app with the sample code. Tap on the widgets to expand them a few times and close using the Done IconButton. After a few times the issue is seen.

Expected results

No exceptions.

Actual results

The following StateError is thrown:

Exception has occurred.
StateError (Bad state: Instance of '_OverlayEntryLocation' is already disposed. Stack trace: #0      _OverlayEntryLocation._dispose.<anonymous closure> (package:flutter/src/widgets/overlay.dart:1739:45)
#1      _OverlayEntryLocation._dispose (package:flutter/src/widgets/overlay.dart:1741:6)
#2      _OverlayPortalState.hide (package:flutter/src/widgets/overlay.dart:1603:21)
#3      OverlayPortalController.hide (package:flutter/src/widgets/overlay.dart:1351:13)
#4      TooltipState._handleStatusChanged (package:flutter/src/material/tooltip.dart:437:30)
#5      AnimationLocalStatusListenersMixin.notifyStatusListeners (package:flutter/src/animation/listener_helpers.dart:240:19)
#6      AnimationController._checkStatusChanged (package:flutter/src/animation/animation_controller.dart:815:7)
#7      AnimationController._tick (package:flutter/src/animation/animation_controller.dart:831:5)
#8      Ticker._tick (package:flutter/src/scheduler/ticker.dart:249:12)
#9      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#10     SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1149:11)
#11     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
#12     SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1147:17)
#13     SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:1064:5)
#14     _invoke1 (dart:ui/hooks.dart:186:13)
#15     PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:374:5)
#16     _beginFrame (dart:ui/hooks.dart:129:31)

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 MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  Future<void> _expandHeroWidget(String tag) {
    final Color barrierColor = Theme.of(context).colorScheme.onBackground.withOpacity(0.25);
    final HeroDialogRoute route = HeroDialogRoute(
      barrierColor: barrierColor,
      builder: (BuildContext context) {
        return Center(
          child: Padding(
            padding: const EdgeInsets.all(20.0),
            child: ConstrainedBox(
              constraints: const BoxConstraints(
                maxWidth: 600.0,
                maxHeight: 400.0,
              ),
              child: Hero(
                tag: tag,
                child: Material(
                  type: MaterialType.canvas,
                  color: Colors.amberAccent,
                  child: Row(
                    children: <Widget>[
                      IconButton(
                        onPressed: () {
                          final SnackBar snackBar = SnackBar(content: Text('SnackBar! $tag'));
                          ScaffoldMessenger.of(context).showSnackBar(snackBar);
                        },
                        icon: const Icon(Icons.abc),
                        tooltip: 'Show a snackbar',
                      ),
                      IconButton(
                        onPressed: () => Navigator.of(context).pop(),
                        icon: const Icon(Icons.check),
                        tooltip: 'Done',
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        );
      },
    );

    return Navigator.of(context).push(route);
  }

  Widget _buildHeroWidget(String tag) {
    return Hero(
      tag: tag,
      child: Container(
        color: Colors.amber,
        width: 300.0,
        height: 200.0,
        child: Material(
          type: MaterialType.transparency,
          child: InkResponse(
            onTap: () => _expandHeroWidget(tag),
            child: RichText(
              text: const TextSpan(text: 'tap me'),
              overflow: TextOverflow.fade,
            ),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[ 
            _buildHeroWidget('widget1'),
            const SizedBox(height: 10.0),
            _buildHeroWidget('widget2'),
            const SizedBox(height: 10.0),
            _buildHeroWidget('widget3'),
          ],
        ),
      ),
    );
  }
}

class HeroDialogRoute<T> extends PageRoute<T> {
  HeroDialogRoute({this.barrierColor = const Color(0x80000000), required this.builder})
      : super();

  final WidgetBuilder builder;

  @override
  bool get opaque => false;

  @override
  bool get barrierDismissible => true;

  @override
  String? get barrierLabel => null;

  @override
  final Color barrierColor;

  @override
  Duration get transitionDuration => const Duration(milliseconds: 200);

  @override
  bool get maintainState => true;

  @override
  Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
    return FadeTransition(
      opacity: CurvedAnimation(parent: animation, curve: Curves.easeOut),
      child: child,
    );
  }

  @override
  Widget buildPage(
    BuildContext context,
    Animation<double> animation,
    Animation<double> secondaryAnimation,
  ) {
    return builder(context);
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
% flutter doctor -v
[✓] Flutter (Channel master, 3.12.0-4.0.pre.102, on macOS 13.4 22F66 darwin-arm64, locale en-ES)
    • Flutter version 3.12.0-4.0.pre.102 on channel master at /Users/tgucio/Library/Frameworks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dc4541fa05 (15 minutes ago), 2023-06-16 19:00:21 +0100
    • Engine revision fb5fed432e
    • Dart version 3.1.0 (build 3.1.0-213.0.dev)
    • DevTools version 2.24.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/tgucio/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.79.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 114.0.5735.133

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: animationAnimation APIsc: crashStack traces logged to the consolec: regressionIt was better in the past than it is nowfound in release: 3.12Found to occur in 3.12frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions