Skip to content

Commit 2b6f789

Browse files
authored
Merge pull request #348 from AhmedLSayed9/enhance/implement_switch_expressions
Implement switch expressions
2 parents 8475b99 + 8344b13 commit 2b6f789

File tree

4 files changed

+31
-57
lines changed

4 files changed

+31
-57
lines changed

packages/dropdown_button2/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- DropdownRoutePage should dispose the created ScrollController [Flutter core].
55
- Remove 'must be non-null' and 'must not be null' comments [Flutter core].
66
- Form fields onChange callback should be called on reset [Flutter core].
7+
- Implement switch expressions.
78

89
## 3.0.0-beta.21
910

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -623,28 +623,19 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>
623623

624624
Color get _iconColor {
625625
// These colors are not defined in the Material Design spec.
626+
final Brightness brightness = Theme.of(context).brightness;
626627
if (_enabled) {
627-
if (_iconStyle.iconEnabledColor != null) {
628-
return _iconStyle.iconEnabledColor!;
629-
}
630-
631-
switch (Theme.of(context).brightness) {
632-
case Brightness.light:
633-
return Colors.grey.shade700;
634-
case Brightness.dark:
635-
return Colors.white70;
636-
}
628+
return _iconStyle.iconEnabledColor ??
629+
switch (brightness) {
630+
Brightness.light => Colors.grey.shade700,
631+
Brightness.dark => Colors.white70,
632+
};
637633
} else {
638-
if (_iconStyle.iconDisabledColor != null) {
639-
return _iconStyle.iconDisabledColor!;
640-
}
641-
642-
switch (Theme.of(context).brightness) {
643-
case Brightness.light:
644-
return Colors.grey.shade400;
645-
case Brightness.dark:
646-
return Colors.white10;
647-
}
634+
return _iconStyle.iconDisabledColor ??
635+
switch (brightness) {
636+
Brightness.light => Colors.grey.shade400,
637+
Brightness.dark => Colors.white10,
638+
};
648639
}
649640
}
650641

packages/dropdown_button2/lib/src/dropdown_menu_item.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,11 @@ class _DropdownItemButton<T> extends StatefulWidget {
148148

149149
class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
150150
void _handleFocusChange(bool focused) {
151-
final bool inTraditionalMode;
152-
switch (FocusManager.instance.highlightMode) {
153-
case FocusHighlightMode.touch:
154-
inTraditionalMode = false;
155-
break;
156-
case FocusHighlightMode.traditional:
157-
inTraditionalMode = true;
158-
break;
159-
}
151+
final bool inTraditionalMode =
152+
switch (FocusManager.instance.highlightMode) {
153+
FocusHighlightMode.touch => false,
154+
FocusHighlightMode.traditional => true,
155+
};
160156

161157
if (focused && inTraditionalMode) {
162158
final _MenuLimits menuLimits = widget.route.getMenuLimits(

packages/dropdown_button2/lib/src/dropdown_route.dart

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -401,49 +401,35 @@ class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate {
401401
assert(textDirection != null);
402402

403403
final Offset offset = route.dropdownStyle.offset;
404-
final double left;
405-
406-
switch (route.dropdownStyle.direction) {
407-
case DropdownDirection.textDirection:
408-
switch (textDirection!) {
409-
case TextDirection.rtl:
410-
left = clampDouble(
404+
final double left = switch (route.dropdownStyle.direction) {
405+
DropdownDirection.textDirection => switch (textDirection!) {
406+
TextDirection.rtl => clampDouble(
411407
buttonRect.right - childSize.width + offset.dx,
412408
0.0,
413409
size.width - childSize.width,
414-
);
415-
break;
416-
case TextDirection.ltr:
417-
left = clampDouble(
410+
),
411+
TextDirection.ltr => clampDouble(
418412
buttonRect.left + offset.dx,
419413
0.0,
420414
size.width - childSize.width,
421-
);
422-
break;
423-
}
424-
break;
425-
case DropdownDirection.right:
426-
left = clampDouble(
415+
),
416+
},
417+
DropdownDirection.right => clampDouble(
427418
buttonRect.left + offset.dx,
428419
0.0,
429420
size.width - childSize.width,
430-
);
431-
break;
432-
case DropdownDirection.left:
433-
left = clampDouble(
421+
),
422+
DropdownDirection.left => clampDouble(
434423
buttonRect.right - childSize.width + offset.dx,
435424
0.0,
436425
size.width - childSize.width,
437-
);
438-
break;
439-
case DropdownDirection.center:
440-
left = clampDouble(
426+
),
427+
DropdownDirection.center => clampDouble(
441428
(size.width - childSize.width) / 2 + offset.dx,
442429
0.0,
443430
size.width - childSize.width,
444-
);
445-
break;
446-
}
431+
),
432+
};
447433

448434
return Offset(left, menuLimits.top);
449435
}

0 commit comments

Comments
 (0)