-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolefound in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/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 teamwaiting for PR to land (fixed)A fix is in flightA fix is in flightworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue
Description
Steps to reproduce
Just use two OverlayPortals which are new builded by parent widget, e.g. on resize like the Switchy widget does.
Tested it with web on Flutter 3.29.0 and 3.22.3, same result.
Expected results
Controller is not attached anymore to old state so on rebuild it can be used again.
Actual results
Exception on rebuild.
Code sample
Code sample
class MainApp extends StatefulWidget {
const MainApp({super.key});
@override
State<MainApp> createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
final OverlayPortalController overlayPortalController = OverlayPortalController();
final OverlayPortalController overlayPortalControllerSecond = OverlayPortalController();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SingleChildScrollView(
child: Switchy(
children: [
PortaledWidget(controller: overlayPortalController),
PortaledWidget(controller: overlayPortalControllerSecond),
],
),
),
);
}
}
class Switchy extends StatelessWidget {
final List<Widget> children;
const Switchy({super.key, required this.children});
@override
Widget build(BuildContext context) {
var size = MediaQuery.sizeOf(context);
if (size.width < 800) {
return Column(children: children);
}
return Row(children: children);
}
}
class PortaledWidget extends StatelessWidget {
final OverlayPortalController controller;
const PortaledWidget({super.key, required this.controller});
@override
Widget build(BuildContext context) {
return OverlayPortal(
controller: controller,
overlayChildBuilder: (context) => ElevatedButton(
onPressed: () => controller.hide(),
child: const Text('cancel'),
),
child: ElevatedButton.icon(onPressed: () => controller.show(), label: const Icon(Icons.home)),
);
}
}Screenshots or Video
Screenshots / Video demonstration
Bildschirmaufnahme.2025-02-28.um.12.57.09.mov
Logs
Logs
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building PortaledWidget:
Assertion failed:
file:///Users/bs000ucwu/flutter/3.29.0/packages/flutter/lib/src/widgets/overlay.dart:1881:7
overlay.dart:1881
controller._attachTarget == null || controller._attachTarget == this
"Failed to attach OverlayPortalController to _OverlayPortalState#73413(lifecycle state: created). It
is already attached to _OverlayPortalState#d6d85."
The relevant error-causing widget was:
PortaledWidget PortaledWidget:file:///Users/bs000ucwu/flutter_test_project/lib/main.dart:25:13
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 307:3 throw_
errors.dart:307
dart-sdk/lib/_internal/js_dev_runtime/private/profile.dart 117:39 assertFailed
profile.dart:117
packages/flutter/src/widgets/overlay.dart 1881:71 [_setupController]
overlay.dart:1881
packages/flutter/src/widgets/overlay.dart 1876:5 initState
overlay.dart:1876
packages/flutter/src/widgets/framework.dart 5860:55 [_firstBuild]
framework.dart:5860
packages/flutter/src/widgets/framework.dart 5709:5 mount
framework.dart:5709
packages/flutter/src/widgets/framework.dart 4555:15 inflateWidget
framework.dart:4555
packages/flutter/src/widgets/framework.dart 4020:18 updateChild
framework.dart:4020
packages/flutter/src/widgets/framework.dart 5756:16 performRebuild
framework.dart:5756
packages/flutter/src/widgets/framework.dart 5445:7 rebuild
framework.dart:5445
packages/flutter/src/widgets/framework.dart 5715:5 [_firstBuild]
framework.dart:5715
packages/flutter/src/widgets/framework.dart 5709:5 mount
framework.dart:5709
packages/flutter/src/widgets/framework.dart 4555:15 inflateWidget
framework.dart:4555
packages/flutter/src/widgets/framework.dart 7178:36 inflateWidget
framework.dart:7178
packages/flutter/src/widgets/framework.dart 7194:32 mount
framework.dart:7194
packages/flutter/src/widgets/framework.dart 4555:15 inflateWidget
framework.dart:4555
packages/flutter/src/widgets/framework.dart 4014:20 updateChild
framework.dart:4014
packages/flutter/src/widgets/framework.dart 5756:16 performRebuild
framework.dart:5756
packages/flutter/src/widgets/framework.dart 5445:7 rebuild
framework.dart:5445
packages/flutter/src/widgets/framework.dart 2704:14 [_tryRebuild]
framework.dart:2704
packages/flutter/src/widgets/framework.dart 2762:11 [_flushDirtyElements]
framework.dart:2762
packages/flutter/src/widgets/framework.dart 3066:17 buildScope
framework.dart:3066
packages/flutter/src/widgets/binding.dart 1229:9 drawFrame
binding.dart:1229
packages/flutter/src/rendering/binding.dart 482:5 [_handlePersistentFrameCallback]
binding.dart:482
packages/flutter/src/scheduler/binding.dart 1442:7 [_invokeFrameCallback]
binding.dart:1442
packages/flutter/src/scheduler/binding.dart 1355:9 handleDrawFrame
binding.dart:1355
packages/flutter/src/scheduler/binding.dart 1208:5 [_handleDrawFrame]
binding.dart:1208
lib/_engine/engine/platform_dispatcher.dart 1347:5 invoke
platform_dispatcher.dart:1347
lib/_engine/engine/platform_dispatcher.dart 301:5 invokeOnDrawFrame
platform_dispatcher.dart:301
lib/_engine/engine/initialization.dart 190:36 <fn>
initialization.dart:190
dart-sdk/lib/_internal/js_dev_runtime/patch/js_allow_interop_patch.dart 224:27 _callDartFunctionFast1
js_allow_interop_patch.dart:224
════════════════════════════════════════════════════════════════════════════════════════════════════
9
Another exception was thrown: Assertion failed: file:///Users/bs000ucwu/flutter/3.29.0/packages/flutter/lib/src/widgets/overlay.dart:1881:7Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-arm64, locale de-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.97.2)
[✓] Connected device (3 available)
[✓] Network resources
• No issues found!Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: crashStack traces logged to the consoleStack traces logged to the consolefound in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/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 teamwaiting for PR to land (fixed)A fix is in flightA fix is in flightworkaround availableThere is a workaround available to overcome the issueThere is a workaround available to overcome the issue