Skip to content

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

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!

Activity

  1. changed the title [-]Enabling or disabling a `Chip` with a tooltip throws an exception [/-] [+]Enabling or disabling a `Chip`/`RawChip` with a tooltip throws an exception [/+] on Nov 11, 2023
  2. danagbemava-nc commented on Nov 13, 2023

    @danagbemava-nc
    Member

    Reproducible using the code sample provided above.

    flutter doctor -v
    [!] Flutter (Channel stable, 3.13.9, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
        • Flutter version 3.13.9 on channel stable at /Users/nexus/dev/sdks/flutter
        ! Warning: `flutter` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/nexus/dev/sdks/flutters/bin/dart, which is not inside your current Flutter SDK checkout at /Users/nexus/dev/sdks/flutter. Consider adding /Users/nexus/dev/sdks/flutter/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d211f42860 (3 weeks ago), 2023-10-25 13:42:25 -0700
        • Engine revision 0545f8705d
        • Dart version 3.1.5
        • DevTools version 2.25.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/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.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.0.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (3 available)
        • Nexus (mobile)  • 00008020-001875E83A38002E • ios            • iOS 17.1.1 21B91
        • macOS (desktop) • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)    • chrome                    • web-javascript • Google Chrome 119.0.6045.123
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
    [✓] Flutter (Channel master, 3.17.0-5.0.pre.64, on macOS 14.0 23A344 darwin-arm64, locale en-GB)
        • Flutter version 3.17.0-5.0.pre.64 on channel master at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 2e088178e8 (7 hours ago), 2023-11-12 18:45:26 -0500
        • Engine revision a18ee3c7f5
        • Dart version 3.3.0 (build 3.3.0-120.0.dev)
        • DevTools version 2.30.0-dev.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc1)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0-rc1
        • Java binary at: /Users/nexus/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.0)
        • Xcode at /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer
        • Build 15A240d
        • CocoaPods version 1.13.0
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.3)
        • Android Studio at /Users/nexus/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.6b829.9-10027231)
    
    [✓] IntelliJ IDEA Ultimate Edition (version 2023.2.3)
        • IntelliJ at /Users/nexus/Applications/IntelliJ IDEA Ultimate.app
        • Flutter plugin version 76.0.4
        • Dart plugin version 232.10072.19
    
    [✓] VS Code (version 1.84.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.76.0
    
    [✓] Connected device (3 available)
        • Nexus (mobile)  • 00008020-001875E83A38002E • ios            • iOS 17.1.1 21B91
        • macOS (desktop) • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
        • Chrome (web)    • chrome                    • web-javascript • Google Chrome 119.0.6045.123
        ! Error: Browsing on the local area network for Dean’s iPad. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    
  3. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: error messageError messages from the Flutter framework
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Nov 13, 2023
  4. self-assigned this
    on Nov 13, 2023
  5. RoarGronmo commented on Nov 15, 2023

    @RoarGronmo

    Is this error related to this error, since this error is also ponting at "AnimationController" ?
    I haven't found any remedy for the "special case", and haven't had time to make a "proof-of-concept" either...

    #135703

  6. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Nov 15, 2023
  7. moved this from To do to In progress in Nevercodeon Nov 21, 2023
  8. moved this from In progress to PR submitted in Nevercodeon Nov 21, 2023
  9. TahaTesser commented on Nov 21, 2023

    @TahaTesser
    Contributor

    Is this error related to this error, since this error is also ponting at "AnimationController" ? I haven't found any remedy for the "special case", and haven't had time to make a "proof-of-concept" either...

    #135703

    I submitted a fix for this #138799. It might also fix the issue you reported. If not, feel free to file a new issue and tag me.

  10. moved this from PR submitted to Done (PR merged) in Nevercodeon Nov 21, 2023
  11. added
    r: fixedIssue is closed as already fixed in a newer version
    on Nov 21, 2023
  12. github-actions commented on Dec 5, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkfound 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 onp: material_uimaterial_ui package in flutter/packagesr: 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