flutter / flutter/flutter

Opening dropdownMenu from alertDialog and rotating the screen throws error.

Open
#171,011 3 comments 0 reactions 0 assignees View on GitHub
a: error message found in release: 3.32 found in release: 3.33 has reproducible steps p: material_ui P2 package team-design triaged-design
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

- run the code sample
- click the button to open dialog
- change screen orientation to landscape

### Expected results

Change of screen orientation should be handled without any problem

### Actual results

Change of screen orientation ends up in an error

### Code sample

Code sample

```dart
import 'package:flutter/material.dart';

void main() => runApp(const App());

class App extends StatefulWidget {
const App({super.key});

@override
State createState() => _AppState();
}

class _AppState extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(home: Scaffold(body: Body()));
}
}

class Body extends StatelessWidget {
const Body({super.key});

@override
Widget build(BuildContext context) {
return SafeArea(
child: Column(
children: [
ElevatedButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Dialog'),
content: Column(
children: [
DropdownButtonFormField(
items:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
.map(
(e) => DropdownMenuItem(
value: e,
child: Text(e.toString()),
),
)
.toList(),
onChanged: (v) {},
),
],
),
);
},
);
},
child: const Text('Open Dialog'),
),
],
),
);
}
}
```

### Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

### Logs

Logs

```console
The following assertion was thrown while notifying listeners for ProxyAnimation:
setState() or markNeedsBuild() called during build.

This ListenableBuilder widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was: ListenableBuilder
listenable: Listenable.merge([AnimationController#a8156(⏭ 1.000; paused; for DialogRoute)➩ProxyAnimation, kAlwaysDismissedAnimation➩ProxyAnimation➩ProxyAnimation])
state: _AnimatedState#30dc2
The widget which was currently being built when the offending call was made was: DropdownButton
dirty
dependencies: [Directionality, DropdownButtonHideUnderline, InheritedCupertinoTheme, MediaQuery, _InheritedTheme, _LocalizationsScope-[GlobalKey#b87b4]]
state: _DropdownButtonState#e665e
When the exception was thrown, this was the stack:
#0 Element.markNeedsBuild. (package:flutter/src/widgets/framework.dart:5271:9)
#1 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:5283:6)
#2 State.setState (package:flutter/src/widgets/framework.dart:1219:15)
#3 _AnimatedState._handleChange (package:flutter/src/widgets/transitions.dart:133:5)
#4 AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:161:19)
#5 AnimationLocalListenersMixin.notifyListeners (package:flutter/src/animation/listener_helpers.dart:161:19)
#6 ProxyAnimation.parent= (package:flutter/src/animation/animations.dart:217:9)
#7 TransitionRoute._setSecondaryAnimation (package:flutter/src/widgets/routes.dart:499:25)
#8 TransitionRoute._updateSecondaryAnimation (package:flutter/src/widgets/routes.dart:491:7)
#9 TransitionRoute.didChangeNext (package:flutter/src/widgets/routes.dart:412:5)
#10 ModalRoute.didChangeNext (package:flutter/src/widgets/routes.dart:2142:11)
#11 NavigatorState._flushRouteAnnouncement (package:flutter/src/widgets/navigator.dart:4593:23)
#12 NavigatorState._flushHistoryUpdates (package:flutter/src/widgets/navigator.dart:4529:5)
#13 NavigatorState.removeRoute (package:flutter/src/widgets/navigator.dart:5641:5)
#14 _DropdownRoute._dismiss (package:flutter/src/material/dropdown.dart:543:18)
#15 _DropdownButtonState._removeDropdownRoute (package:flutter/src/material/dropdown.dart:1351:21)
#16 _DropdownButtonState.build (package:flutter/src/material/dropdown.dart:1504:7)
#17 StatefulElement.build (package:flutter/src/widgets/framework.dart:5823:27)
#18 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5715:15)
#19 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5874:11)
#20 Element.rebuild (package:flutter/src/widgets/framework.dart:5427:7)
#21 BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2694:15)
#22 BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
#23 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3056:18)
#24 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1240:21)
#25 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:495:5)
#26 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1438:15)
#27 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1351:9)
#28 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1204:5)
#29 _invoke (dart:ui/hooks.dart:331:13)
#30 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:444:5)
#31 _drawFrame (dart:ui/hooks.dart:303:31)
The ProxyAnimation notifying listeners was: kAlwaysDismissedAnimation➩ProxyAnimation➩ProxyAnimation
```

### Flutter Doctor output

Doctor output

```console
Flutter: 3.32.4
Dart: 3.8.1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.