@@ -147,6 +147,46 @@ class _DropdownItemButton<T> extends StatefulWidget {
147
147
}
148
148
149
149
class _DropdownItemButtonState <T > extends State <_DropdownItemButton <T >> {
150
+ late CurvedAnimation _opacityAnimation;
151
+
152
+ @override
153
+ void initState () {
154
+ super .initState ();
155
+ _setOpacityAnimation ();
156
+ }
157
+
158
+ @override
159
+ void didUpdateWidget (_DropdownItemButton <T > oldWidget) {
160
+ super .didUpdateWidget (oldWidget);
161
+ if (oldWidget.itemIndex != widget.itemIndex ||
162
+ oldWidget.route.animation != widget.route.animation ||
163
+ oldWidget.route.selectedIndex != widget.route.selectedIndex ||
164
+ widget.route.items.length != oldWidget.route.items.length ||
165
+ widget.route.dropdownStyle.openInterval.end !=
166
+ oldWidget.route.dropdownStyle.openInterval.end) {
167
+ _opacityAnimation.dispose ();
168
+ _setOpacityAnimation ();
169
+ }
170
+ }
171
+
172
+ @override
173
+ void dispose () {
174
+ _opacityAnimation.dispose ();
175
+ super .dispose ();
176
+ }
177
+
178
+ void _setOpacityAnimation () {
179
+ final double menuCurveEnd = widget.route.dropdownStyle.openInterval.end;
180
+ final double unit = 0.5 / (widget.route.items.length + 1.5 );
181
+ final double start =
182
+ clampDouble (menuCurveEnd + (widget.itemIndex + 1 ) * unit, 0.0 , 1.0 );
183
+ final double end = clampDouble (start + 1.5 * unit, 0.0 , 1.0 );
184
+ _opacityAnimation = CurvedAnimation (
185
+ parent: widget.route.animation! ,
186
+ curve: Interval (start, end),
187
+ );
188
+ }
189
+
150
190
void _handleFocusChange (bool focused) {
151
191
final bool inTraditionalMode =
152
192
switch (FocusManager .instance.highlightMode) {
@@ -197,15 +237,7 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
197
237
198
238
@override
199
239
Widget build (BuildContext context) {
200
- final double menuCurveEnd = widget.route.dropdownStyle.openInterval.end;
201
-
202
240
final DropdownItem <T > dropdownItem = widget.route.items[widget.itemIndex];
203
- final double unit = 0.5 / (widget.route.items.length + 1.5 );
204
- final double start =
205
- clampDouble (menuCurveEnd + (widget.itemIndex + 1 ) * unit, 0.0 , 1.0 );
206
- final double end = clampDouble (start + 1.5 * unit, 0.0 , 1.0 );
207
- final CurvedAnimation opacity = CurvedAnimation (
208
- parent: widget.route.animation! , curve: Interval (start, end));
209
241
210
242
Widget child = Container (
211
243
padding: (menuItemStyle.padding ?? _kMenuItemPadding)
@@ -230,7 +262,7 @@ class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
230
262
: child,
231
263
);
232
264
}
233
- child = FadeTransition (opacity: opacity , child: child);
265
+ child = FadeTransition (opacity: _opacityAnimation , child: child);
234
266
if (kIsWeb && dropdownItem.enabled) {
235
267
child = Shortcuts (
236
268
shortcuts: _webShortcuts,
0 commit comments