Skip to content

Enabling or disabling a Chip/RawChip with a tooltip throws an exception  #138287

@amal-stack

Description

@amal-stack

Is there an existing issue for this?

Steps to reproduce

  1. Create a RawChip or one of the Chip widgets that uses the underlying RawChip's isEnabled property, like ActionChip.
  2. Supply a tooltip for the chip.
  3. Initialize a state variable (via a simple stateful widget or provider) that indicates the chip status (enabled/disabled) and supply a conditional callback for onPressed to enable/disable the chip as setting the onPressed to null is equivalent to disabling the chip.
bool isChipEnabled = true;
...
ActionChip(
    label: const Text('Show message'),
    tooltip: 'Show message in snack bar',    // This is required to reproduce the error
    onPressed: isChipEnabled ? _onPressedCallback : null  
)
  1. Create another supporting widget that controls enabling or disabling the chip:
FloatingActionButton(
        onPressed: () => setState(() => isChipEnabled = !isChipEnabled),
        tooltip: 'Enable/disable tooltip',
        child: const Icon(Icons.change_circle),
)

(Full example in code section)

Expected results

When the state variable changes, the chip's enabled/disabled status should change without throwing an exception.

Actual results

When the chip's state is toggled via the supporting widget (here: FloatingActionButton), the framework (RenderObject.markNeedsPaint) throws an exception. This is possibly happening because the render object (_RenderChip) is somehow prematurely disposed:

[+34179 ms] ══╡ EXCEPTION CAUGHT BY ANIMATION LIBRARY ╞═════════════════════════════════════════════════════════
                     The following assertion was thrown while notifying listeners for AnimationController:
                     'package:flutter/src/rendering/object.dart': Failed assertion: line 2901 pos 12: '!_debugDisposed':
                     is not true.

                     Either the assertion indicates an error in the framework itself, or we should provide substantially
                     more information in this error message to help you determine and fix the underlying cause.
                     In either case, please report this assertion by filing a bug on GitHub:
                       https://github.com/flutter/flutter/issues/new?template=2_bug.yml

                     When the exception was thrown, this was the stack:
                     #2      RenderObject.markNeedsPaint (package:flutter/src/rendering/object.dart:2901:12)
                     #3      AnimationLocalListenersMixin.notifyListeners
(package:flutter/src/animation/listener_helpers.dart:161:19)
                     #4      AnimationController._tick (package:flutter/src/animation/animation_controller.dart:830:5)
                     #5      Ticker._tick (package:flutter/src/scheduler/ticker.dart:249:12)
                     #6      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
                     #7      SchedulerBinding.handleBeginFrame.<anonymous closure>
(package:flutter/src/scheduler/binding.dart:1149:11)
                     #8      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:625:13)
                     #9      SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1147:17)
                     #10     SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:1064:5)
                     #11     _invoke1 (dart:ui/hooks.dart:186:13)
                     #12     PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:379:5)
                     #13     _beginFrame (dart:ui/hooks.dart:129:31)
                     (elided 2 frames from class _AssertionError)

                     The AnimationController notifying listeners was:
                       AnimationController#95659(⏮ 0.000; paused)

════════════════════════════════════════════════════════════════════════════════════════════════════

This only happens when the chip has a tooltip. A little bit of debugging shows that the error is apparently thrown when the chip in the widget tree is replaced with a new chip from _RenderChipState.didUpdateWidget method when an AnimationController's reverse() method is called (enableController.reverse()). Here is the stack as obtained by the _FrameCallbackEntry's debugStack property that throws the error:

View debug stack
#0      new _FrameCallbackEntry.<anonymous closure> (package:flutter/src/scheduler/binding.dart:122:33)
#1      new _FrameCallbackEntry (package:flutter/src/scheduler/binding.dart:125:6)
#2      SchedulerBinding.scheduleFrameCallback (package:flutter/src/scheduler/binding.dart:580:49)
#3      Ticker.scheduleTick (package:flutter/src/scheduler/ticker.dart:265:46)
#4      Ticker.start (package:flutter/src/scheduler/ticker.dart:171:7)
#5      AnimationController._startSimulation (package:flutter/src/animation/animation_controller.dart:745:42)
#6      AnimationController._animateToInternal (package:flutter/src/animation/animation_controller.dart:612:12)
#7      AnimationController.reverse (package:flutter/src/animation/animation_controller.dart:495:12)
#8      _RawChipState.didUpdateWidget.<anonymous closure> (package:flutter/src/material/chip.dart:1077:28)
#9      State.setState (package:flutter/src/widgets/framework.dart:1138:30)
#10     _RawChipState.didUpdateWidget (package:flutter/src/material/chip.dart:1072:7)
#11     StatefulElement.update (package:flutter/src/widgets/framework.dart:5471:55)
#12     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#13     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#14     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#15     StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
#16     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#17     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#18     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#19     StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
#20     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#21     Element.updateChildren (package:flutter/src/widgets/framework.dart:3834:32)
#22     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6594:17)
#23     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#24     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#25     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#26     StatelessElement.update (package:flutter/src/widgets/framework.dart:5373:5)
#27     Element.updateChild (package:flutter/src/widgets/framework.dart:3685:15)
#28     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5322:16)
#29     Element.rebuild (package:flutter/src/widgets/framework.dart:5016:7)
#30     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2779:19)
#31     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:916:21)
#32     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:360:5)
#33     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1297:15)
#34     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1227:9)
#35     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1085:5)
#36     _invoke (dart:ui/hooks.dart:170:13)
#37     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:401:5)
#38     _drawFrame (dart:ui/hooks.dart:140: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.lime),
        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> {

  bool _enableChip = true;

  void _showSnackBar() => ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Chip pressed')));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: ActionChip(
          tooltip: 'Tooltip',
          onPressed: _enableChip ? _showSnackBar : null,
          label: const Text('Show snack bar'),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => setState(() => _enableChip = !_enableChip),
        tooltip: 'Increment',
        child: const Icon(Icons.change_circle),
      ), 
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs

https://pastebin.com/ypH5DVBc

Flutter Doctor output

Doctor output
> flutter doctor -v
[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [Version 10.0.22631.2506], locale en-IN)
    • Flutter version 3.13.9 on channel stable at C:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (2 weeks ago), 2023-10-25 13:42:25 -0700
    • Engine revision 0545f8705d
    • Dart version 3.1.5
    • DevTools version 2.25.0

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\amalk\AppData\Local\Android\Sdk
    • Platform android-33, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\amalk\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-b2043.56-9586694)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • CHROME_EXECUTABLE = C:\Program Files\Google\Chrome Dev\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.6.5)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.6.33829.357
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2022.2)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • 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-b2043.56-9586694)

[√] IntelliJ IDEA Community Edition (version 2023.1)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.2
    • 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

[√] IntelliJ IDEA Ultimate Edition (version 2023.1)
    • IntelliJ at C:\Users\amalk\AppData\Local\JetBrains\Toolbox\apps\IDEA-U\ch-0\231.8109.175
    • 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

[√] VS Code (version 1.84.1)
    • VS Code at C:\Users\amalk\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.76.0

[√] Connected device (4 available)
    • Pixel 7a (mobile) • 32201JEHN15591 • android-arm64  • Android 14 (API 34)
    • Windows (desktop) • windows        • windows-x64    • Microsoft Windows [Version 10.0.22631.2506]
    • Chrome (web)      • chrome         • web-javascript • unknown
    • Edge (web)        • edge           • web-javascript • Microsoft Edge 119.0.2151.44

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

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkf: material designflutter/packages/flutter/material repository.found in release: 3.13Found to occur in 3.13found in release: 3.17Found to occur in 3.17frameworkflutter/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-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions