-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Steps to reproduce
- Add a
DropdownMenuand assign it aTextEditingController. - Define a list of
DropdownMenuEntry. Important: this list is dynamic, and re-created with each build. - Wrap the menu with a
ListenableBuilderthat listens to the text controller.
Expected results
The DropdownMenu should be built a single time.
Our dropdown menu uses the user input to fetch some paged data, which then creates a list of new options based on their input. I expect that changing the options should not result in the user's input being cleared; this makes it impossible for them to search for an item.
- (Related, but only tangentially: if the options are changed, I expect that the new options are filtered by the existing
TextEditingValue. The pre 3.27.0 solution of not doing anything would also be remedial.)
Actual results
Instead, the DropdownMenu enters an infinite loop, spitting out the following error (full stack trace below):
======== Exception caught by widgets library =======================================================
The following assertion was thrown while rebuilding dirty elements:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5356 pos 12: '!_dirty': is not true.
Whenever the list of options change (read: every call to build, due to list equality), the text controller's value is reset to the initial value (null). As a result, the listenable builder is rebuilt, starting the process again.
If there is a delay between modifying the TextEditingController and rebuilding the widget (as is the case in my production code), the widget will silently build forever, resetting the text input to empty every frame.
This issue can be mitigated by:
- Defining the list of entries outside of build, such that the list is not recreated when the widget is built.
- Refactoring my page such that the
DropdownMenuis not a child of theListenableBuilder. This is not practical for my use case :/
Code sample
Code sample
class InfiniteBuildWidget extends StatelessWidget {
InfiniteBuildWidget({super.key});
final controller = TextEditingController();
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: controller,
builder: (context, _) {
return DropdownMenu(
enableFilter: true,
controller: controller,
dropdownMenuEntries: [
for (final i in [1, 2, 3])
DropdownMenuEntry(value: i, label: 'Item number $i')
],
);
},
);
}
}Screenshots or Video
No response
Logs
Stack Trace
======== Exception caught by widgets library =======================================================
The following assertion was thrown while rebuilding dirty elements:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5356 pos 12: '!_dirty': 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
The relevant error-causing widget was:
ListenableBuilder ListenableBuilder:file:///Users/stephen/MosaicSoftware/mpui/mp_operations_console/lib/screens/workbench/workbench_page.dart:77:12
When the exception was thrown, this was the stack:
#2 Element.rebuild (package:flutter/src/widgets/framework.dart:5356:12)
#3 BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2694:15)
#4 BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2753:11)
#5 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
#6 _LayoutBuilderElement._rebuildWithConstraints (package:flutter/src/widgets/layout_builder.dart:239:12)
#7 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:2738:59)
#8 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:1108:15)
#9 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2738:14)
#10 RenderConstrainedLayoutBuilder.rebuildIfNecessary (package:flutter/src/widgets/layout_builder.dart:286:5)
#11 _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:377:5)
#12 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2465:7)
#13 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1062:18)
#14 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1075:15)
#15 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:609:23)
#16 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1178:13)
#17 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:475:5)
#18 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#19 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
#20 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#21 _invoke (dart:ui/hooks.dart:312:13)
#22 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:427:5)
#23 _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)
The element being rebuilt at the time was: ListenableBuilder
listenable: TextEditingController#5150f(TextEditingValue(text: ┤├, selection: TextSelection.collapsed(offset: 0, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1)))
dirty
state: _AnimatedState#3590d
====================================================================================================
Flutter Doctor output
Doctor output
Edited.flutter doctor -v
[✓] Flutter (Channel stable, 3.27.0, on macOS 15.1.1 24B91 darwin-arm64, locale en-US)
• Flutter version 3.27.0 on channel stable at ~/Development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 8495dee1fd (2 days ago), 2024-12-10 14:23:39 -0800
• Engine revision 83bacfc525
• Dart version 3.6.0
• DevTools version 2.40.2
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at ~/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home/bin/java
• Java version Java(TM) SE Runtime Environment (build 17.0.5+9-LTS-191)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2024.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 21.0.3+-79915917-b509.11)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.3)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 82.2.4
• Dart plugin version 243.22562.3
[✓] IntelliJ IDEA Community Edition (version 2022.3.1)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• 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
[✓] Connected device (3 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 15.1.1 24B91 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 15.1.1 24B91 darwin-arm64
• Chrome (web) • chrome • web-javascript • Google Chrome 131.0.6778.109
! Error: Browsing on the local area network for [coworker's phone]. 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.Metadata
Metadata
Assignees
Labels
Type
Projects
Status