Skip to content

Implement switch expressions #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/dropdown_button2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- DropdownRoutePage should dispose the created ScrollController [Flutter core].
- Remove 'must be non-null' and 'must not be null' comments [Flutter core].
- Form fields onChange callback should be called on reset [Flutter core].
- Implement switch expressions.

## 3.0.0-beta.21

Expand Down
31 changes: 11 additions & 20 deletions packages/dropdown_button2/lib/src/dropdown_button2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -623,28 +623,19 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>>

Color get _iconColor {
// These colors are not defined in the Material Design spec.
final Brightness brightness = Theme.of(context).brightness;
if (_enabled) {
if (_iconStyle.iconEnabledColor != null) {
return _iconStyle.iconEnabledColor!;
}

switch (Theme.of(context).brightness) {
case Brightness.light:
return Colors.grey.shade700;
case Brightness.dark:
return Colors.white70;
}
return _iconStyle.iconEnabledColor ??
switch (brightness) {
Brightness.light => Colors.grey.shade700,
Brightness.dark => Colors.white70,
};
} else {
if (_iconStyle.iconDisabledColor != null) {
return _iconStyle.iconDisabledColor!;
}

switch (Theme.of(context).brightness) {
case Brightness.light:
return Colors.grey.shade400;
case Brightness.dark:
return Colors.white10;
}
return _iconStyle.iconDisabledColor ??
switch (brightness) {
Brightness.light => Colors.grey.shade400,
Brightness.dark => Colors.white10,
};
}
}

Expand Down
14 changes: 5 additions & 9 deletions packages/dropdown_button2/lib/src/dropdown_menu_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,11 @@ class _DropdownItemButton<T> extends StatefulWidget {

class _DropdownItemButtonState<T> extends State<_DropdownItemButton<T>> {
void _handleFocusChange(bool focused) {
final bool inTraditionalMode;
switch (FocusManager.instance.highlightMode) {
case FocusHighlightMode.touch:
inTraditionalMode = false;
break;
case FocusHighlightMode.traditional:
inTraditionalMode = true;
break;
}
final bool inTraditionalMode =
switch (FocusManager.instance.highlightMode) {
FocusHighlightMode.touch => false,
FocusHighlightMode.traditional => true,
};

if (focused && inTraditionalMode) {
final _MenuLimits menuLimits = widget.route.getMenuLimits(
Expand Down
42 changes: 14 additions & 28 deletions packages/dropdown_button2/lib/src/dropdown_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,49 +401,35 @@ class _DropdownMenuRouteLayout<T> extends SingleChildLayoutDelegate {
assert(textDirection != null);

final Offset offset = route.dropdownStyle.offset;
final double left;

switch (route.dropdownStyle.direction) {
case DropdownDirection.textDirection:
switch (textDirection!) {
case TextDirection.rtl:
left = clampDouble(
final double left = switch (route.dropdownStyle.direction) {
DropdownDirection.textDirection => switch (textDirection!) {
TextDirection.rtl => clampDouble(
buttonRect.right - childSize.width + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case TextDirection.ltr:
left = clampDouble(
),
TextDirection.ltr => clampDouble(
buttonRect.left + offset.dx,
0.0,
size.width - childSize.width,
);
break;
}
break;
case DropdownDirection.right:
left = clampDouble(
),
},
DropdownDirection.right => clampDouble(
buttonRect.left + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case DropdownDirection.left:
left = clampDouble(
),
DropdownDirection.left => clampDouble(
buttonRect.right - childSize.width + offset.dx,
0.0,
size.width - childSize.width,
);
break;
case DropdownDirection.center:
left = clampDouble(
),
DropdownDirection.center => clampDouble(
(size.width - childSize.width) / 2 + offset.dx,
0.0,
size.width - childSize.width,
);
break;
}
),
};

return Offset(left, menuLimits.top);
}
Expand Down