Repository navigation
Throwing in didChangeDependencies after establishing dependencies causes failures during test teardown #65655
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: crashStack traces logged to the consoleStack traces logged to the consolefound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
goderbauer
opened on Sep 11, 2020
Issue body actions
Reactions are currently unavailable
Activity
- addeda: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: crashStack traces logged to the consoleStack traces logged to the consoleframeworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
on Sep 11, 2020 code sample
import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('example', (WidgetTester tester) async { await tester.pumpWidget(Foo(child: Bar())); expect(tester.takeException(), isFlutterError); // Work around: // await tester.pumpWidget(Container()); // expect(tester.takeException(), isAssertionError); }); } class Foo extends InheritedWidget { const Foo({Widget child}) : super(child: child); static Foo of(BuildContext context) { return context.dependOnInheritedWidgetOfExactType<Foo>(); } @override bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; } class Bar extends StatefulWidget { @override State<StatefulWidget> createState() => BarState(); } class BarState extends State<Bar> { Foo currentFoo; @override void didChangeDependencies() { super.didChangeDependencies(); currentFoo = Foo.of(context); throw FlutterError('something went wrong'); } @override Widget build(BuildContext context) { return Container(); } }
logs
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown attaching to the render tree: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5098 pos 14: '_dependents.isEmpty': 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=BUG.md When the exception was thrown, this was the stack: #2 InheritedElement.debugDeactivated.<anonymous closure> (package:flutter/src/widgets/framework.dart:5098:14) #3 InheritedElement.debugDeactivated (package:flutter/src/widgets/framework.dart:5100:6) #4 _InactiveElements._deactivateRecursively.<anonymous closure> (package:flutter/src/widgets/framework.dart:2020:15) #5 _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:2022:6) #6 _InactiveElements.add (package:flutter/src/widgets/framework.dart:2030:7) #7 Element.deactivateChild (package:flutter/src/widgets/framework.dart:3605:29) #8 Element.updateChild (package:flutter/src/widgets/framework.dart:3322:9) #9 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1252:16) #10 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1230:5) #11 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1244:7) #12 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) #13 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33) #14 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1088:18) #15 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5) #16 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15) #17 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9) #18 AutomatedTestWidgetsFlutterBinding.scheduleWarmUpFrame (package:flutter_test/src/binding.dart:1036:5) #19 runApp (package:flutter/src/widgets/binding.dart:1063:7) #20 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:791:7) <asynchronous suspension> #23 TestWidgetsFlutterBinding._runTest (package:flutter_test/src/binding.dart:764:14) #24 AutomatedTestWidgetsFlutterBinding.runTest.<anonymous closure> (package:flutter_test/src/binding.dart:1173:24) #25 FakeAsync.run.<anonymous closure>.<anonymous closure> (package:fake_async/fake_async.dart:178:54) #30 withClock (package:clock/src/default.dart:48:10) #31 FakeAsync.run.<anonymous closure> (package:fake_async/fake_async.dart:178:22) #36 FakeAsync.run (package:fake_async/fake_async.dart:178:7) #37 AutomatedTestWidgetsFlutterBinding.runTest (package:flutter_test/src/binding.dart:1170:15) #38 testWidgets.<anonymous closure> (package:flutter_test/src/widget_tester.dart:138:24) #39 Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart:175:19) <asynchronous suspension> #40 Declarer.test.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/declarer.dart) #45 Declarer.test.<anonymous closure> (package:test_api/src/backend/declarer.dart:173:13) #46 Invoker.waitForOutstandingCallbacks.<anonymous closure> (package:test_api/src/backend/invoker.dart:231:15) #51 Invoker.waitForOutstandingCallbacks (package:test_api/src/backend/invoker.dart:228:5) #52 Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:383:17) <asynchronous suspension> #53 Invoker._onRun.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart) #58 Invoker._onRun.<anonymous closure>.<anonymous closure> (package:test_api/src/backend/invoker.dart:370:9) #59 Invoker._guardIfGuarded (package:test_api/src/backend/invoker.dart:415:15) #60 Invoker._onRun.<anonymous closure> (package:test_api/src/backend/invoker.dart:369:7) #67 Invoker._onRun (package:test_api/src/backend/invoker.dart:368:11) #68 LiveTestController.run (package:test_api/src/backend/live_test_controller.dart:153:11) #69 RemoteListener._runLiveTest.<anonymous closure> (package:test_api/src/remote_listener.dart:256:16) #74 RemoteListener._runLiveTest (package:test_api/src/remote_listener.dart:255:5) #75 RemoteListener._serializeTest.<anonymous closure> (package:test_api/src/remote_listener.dart:208:7) #93 _GuaranteeSink.add (package:stream_channel/src/guarantee_channel.dart:125:12) #94 new _MultiChannel.<anonymous closure> (package:stream_channel/src/multi_channel.dart:159:31) #98 CastStreamSubscription._onData (dart:_internal/async_cast.dart:85:11) #132 new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1145:21) #140 _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:338:23) #141 _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:232:46) #151 _Socket._onData (dart:io-patch/socket_patch.dart:2150:41) #160 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1686:33) #161 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1182:14) (elided 113 frames from class _AssertionError, dart:async, and package:stack_trace) ════════════════════════════════════════════════════════════════════════════════════════════════════ Test failed. See exception logs above. The test description was: example ✖ example Exited (1)
flutter doctor -v
[✓] Flutter (Channel master, 1.22.0-10.0.pre.138, on Mac OS X 10.15.6 19G2021, locale en-GB) • Flutter version 1.22.0-10.0.pre.138 at /Users/tahatesser/Code/flutter_master • Framework revision 620cd16cf0 (3 days ago), 2020-09-11 10:35:03 -0400 • Engine revision a0bd862cc0 • Dart version 2.10.0 (build 2.10.0-115.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/tahatesser/Code/sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = /Users/tahatesser/Code/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 11.7) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.7, Build version 11E801a • CocoaPods version 1.9.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.0) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 49.0.2 • Dart plugin version 193.7547 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] VS Code (version 1.49.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.14.1 [✓] Connected device (4 available) • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 10 (API 29) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G2021 • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 85.0.4183.102 • No issues found!- addedfound in release: 1.22Found to occur in 1.22Found to occur in 1.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
on Sep 14, 2020 - addedP2Important issues not at the top of the work listImportant issues not at the top of the work list
on Aug 2, 2022 Verified this issue using latest versions and observed that error persists.
console error log
Testing started at 4:20 PM ... /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter --no-color test --machine --start-paused test/widget_test.dart ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building View-[GlobalObjectKey TestWindow#bab02]: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5430 pos 14: '_dependents.isEmpty': 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.md When the exception was thrown, this was the stack: #2 InheritedElement.debugDeactivated.<anonymous closure> (package:flutter/src/widgets/framework.dart:5430:14) #3 InheritedElement.debugDeactivated (package:flutter/src/widgets/framework.dart:5432:6) #4 _InactiveElements._deactivateRecursively.<anonymous closure> (package:flutter/src/widgets/framework.dart:1982:15) #5 _InactiveElements._deactivateRecursively (package:flutter/src/widgets/framework.dart:1984:6) #6 _InactiveElements.add (package:flutter/src/widgets/framework.dart:1992:7) #7 Element.deactivateChild (package:flutter/src/widgets/framework.dart:4020:30) #8 Element.updateChild (package:flutter/src/widgets/framework.dart:3695:9) #9 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5020:16) #10 Element.rebuild (package:flutter/src/widgets/framework.dart:4715:7) #11 ProxyElement.update (package:flutter/src/widgets/framework.dart:5328:5) #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3684:15) #13 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1194:16) #14 RenderObjectToWidgetElement.update (package:flutter/src/widgets/binding.dart:1171:5) #15 RenderObjectToWidgetElement.performRebuild (package:flutter/src/widgets/binding.dart:1185:7) #16 Element.rebuild (package:flutter/src/widgets/framework.dart:4715:7) #17 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2767:19) #18 AutomatedTestWidgetsFlutterBinding.drawFrame (package:flutter_test/src/binding.dart:1336:19) #19 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:381:5) #20 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15) #21 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1218:9) #22 AutomatedTestWidgetsFlutterBinding.scheduleWarmUpFrame (package:flutter_test/src/binding.dart:1282:5) #23 runApp (package:flutter/src/widgets/binding.dart:1037:7) #24 TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:942:7) <asynchronous suspension> (elided 2 frames from class _AssertionError) ════════════════════════════════════════════════════════════════════════════════════════════════════ Test failed. See exception logs above. The test description was: examplerunnable code sample
import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets('example', (WidgetTester tester) async { await tester.pumpWidget(Foo(child: Bar())); expect(tester.takeException(), isFlutterError); // Work around: // await tester.pumpWidget(Container()); // expect(tester.takeException(), isAssertionError); }); } class Foo extends InheritedWidget { const Foo({required Widget child}) : super(child: child); static Foo? of(BuildContext context) { return context.dependOnInheritedWidgetOfExactType<Foo>(); } @override bool updateShouldNotify(covariant InheritedWidget oldWidget) => false; } class Bar extends StatefulWidget { @override State<StatefulWidget> createState() => BarState(); } class BarState extends State<Bar> { Foo? currentFoo; @override void didChangeDependencies() { super.didChangeDependencies(); currentFoo = Foo.of(context); throw FlutterError('something went wrong'); } @override Widget build(BuildContext context) { return Container(); } }stable, master flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.3.10 on channel stable at /Users/dhs/documents/fluttersdk/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 135454af32 (15 hours ago), 2022-12-15 07:36:55 -0800 • Engine revision 3316dd8728 • Dart version 2.18.6 • DevTools version 2.15.0 [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. [!] Flutter (Channel master, 3.7.0-14.0.pre.30, on macOS 12.2.1 21D62 darwin-x64, locale en-GB) • Flutter version 3.7.0-14.0.pre.30 on channel master at /Users/dhs/documents/fluttersdk/flutter ! Warning: `flutter` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter. Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision c53501d835 (83 minutes ago), 2023-01-03 23:00:08 -0500 • Engine revision 32c468507b • Dart version 3.0.0 (build 3.0.0-77.0.dev) • DevTools version 2.20.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. [!] Xcode - develop for iOS and macOS (Xcode 12.3) • Xcode at /Applications/Xcode.app/Contents/Developer ! Flutter recommends a minimum Xcode version of 13. Download the latest version or update via the Mac App Store. • CocoaPods version 1.11.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] VS Code (version 1.62.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.21.0 [✓] Connected device (5 available) • SM G975F (mobile) • RZ8M802WY0X • android-arm64 • Android 11 (API 30) • Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios • iOS 14.4.1 18D61 • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator) • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.4 19E2269 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 98.0.4758.80 [✓] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category.- addedfound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7and removedfound in release: 1.22Found to occur in 1.22Found to occur in 1.22
on Jan 4, 2023 - addedteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
on Jul 8, 2023 - added a commit that references this issue
on Aug 14, 2025 - added a commit that references this issue
on Aug 14, 2025 - addedr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer version
on Aug 15, 2025 - added a commit that references this issue
on Aug 19, 2025 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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Aug 29, 2025 - added a commit that references this issue
on Sep 18, 2025 - added a commit that references this issue
on Sep 22, 2025 - added a commit that references this issue
on Nov 21, 2025
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our testsc: crashStack traces logged to the consoleStack traces logged to the consolefound in release: 3.3Found to occur in 3.3Found to occur in 3.3found in release: 3.7Found to occur in 3.7Found to occur in 3.7frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team