diff --git a/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart b/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart index 344ef8ec79..caa20e1278 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart @@ -209,11 +209,13 @@ class ListItem extends StatelessWidget { } String _convertCountToStr(int count) { - return switch (count) { - < 10000 => count.toString(), - < 100000 => '${(count / 10000).toStringAsPrecision(2)}w', - _ => '${(count / 10000).floor()}w', - }; + if (count < 10000) { + return count.toString(); + } else if (count < 100000) { + return '${(count / 10000).toStringAsPrecision(2)}w'; + } else { + return '${(count / 10000).floor()}w'; + } } Widget _buildUserInfo() { diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart index 1ba7bf8ceb..3bf1feaca2 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_build_material_checkbox.dart @@ -31,11 +31,13 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder { } Row _buildRow() { - _isChecked = switch (_isChecked) { - null => true, - true => false, - false => null, - }; + if (_isChecked == null) { + _isChecked = true; + } else if (_isChecked!) { + _isChecked = false; + } else { + _isChecked = null; + } return Row( children: List.generate(10, (int i) { diff --git a/dev/conductor/core/lib/src/start.dart b/dev/conductor/core/lib/src/start.dart index 01446d846e..bace0a29e0 100644 --- a/dev/conductor/core/lib/src/start.dart +++ b/dev/conductor/core/lib/src/start.dart @@ -255,14 +255,16 @@ class StartContext extends Context { if (atBranchPoint) { return ReleaseType.BETA_INITIAL; } - if (releaseChannel != 'stable') { - return ReleaseType.BETA_HOTFIX; + + if (releaseChannel == 'stable') { + if (lastVersion.type == VersionType.stable) { + return ReleaseType.STABLE_HOTFIX; + } else { + return ReleaseType.STABLE_INITIAL; + } } - return switch (lastVersion.type) { - VersionType.stable => ReleaseType.STABLE_HOTFIX, - VersionType.development || VersionType.gitDescribe || VersionType.latest => ReleaseType.STABLE_INITIAL, - }; + return ReleaseType.BETA_HOTFIX; } Future run() async { diff --git a/dev/integration_tests/flutter_gallery/lib/demo/material/backdrop_demo.dart b/dev/integration_tests/flutter_gallery/lib/demo/material/backdrop_demo.dart index 2bba5ad87c..ded1a7b05e 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/material/backdrop_demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/material/backdrop_demo.dart @@ -307,11 +307,13 @@ class _BackdropDemoState extends State with SingleTickerProviderSt } final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight; - _controller.fling(velocity: switch (flingVelocity) { - < 0.0 => math.max(2.0, -flingVelocity), - > 0.0 => math.min(-2.0, -flingVelocity), - _ => _controller.value < 0.5 ? -2.0 : 2.0, - }); + if (flingVelocity < 0.0) { + _controller.fling(velocity: math.max(2.0, -flingVelocity)); + } else if (flingVelocity > 0.0) { + _controller.fling(velocity: math.min(-2.0, -flingVelocity)); + } else { + _controller.fling(velocity: _controller.value < 0.5 ? -2.0 : 2.0); + } } // Stacks a BackdropPanel, which displays the selected category, on top diff --git a/dev/integration_tests/flutter_gallery/lib/demo/material/list_demo.dart b/dev/integration_tests/flutter_gallery/lib/demo/material/list_demo.dart index 2c46f28710..9a81048b4c 100644 --- a/dev/integration_tests/flutter_gallery/lib/demo/material/list_demo.dart +++ b/dev/integration_tests/flutter_gallery/lib/demo/material/list_demo.dart @@ -184,18 +184,21 @@ class _ListDemoState extends State { } Widget buildListTile(BuildContext context, String item) { - final String? subtitle = switch (_itemType) { - _MaterialListType.oneLine || _MaterialListType.oneLineWithAvatar || null => null, - _MaterialListType.twoLine => 'Additional item information.', - _MaterialListType.threeLine => 'Even more additional list item information appears on line three.', - }; + Widget? secondary; + if (_itemType == _MaterialListType.twoLine) { + secondary = const Text('Additional item information.'); + } else if (_itemType == _MaterialListType.threeLine) { + secondary = const Text( + 'Even more additional list item information appears on line three.', + ); + } return MergeSemantics( child: ListTile( isThreeLine: _itemType == _MaterialListType.threeLine, dense: _dense, leading: _showAvatars != null ? ExcludeSemantics(child: CircleAvatar(child: Text(item))) : null, title: Text('This item represents $item.'), - subtitle: subtitle != null ? Text(subtitle) : null, + subtitle: secondary, trailing: _showIcons != null ? Icon(Icons.info, color: Theme.of(context).disabledColor) : null, ), ); diff --git a/dev/integration_tests/flutter_gallery/lib/gallery/backdrop.dart b/dev/integration_tests/flutter_gallery/lib/gallery/backdrop.dart index 917e9ffd2c..7f6a56303d 100644 --- a/dev/integration_tests/flutter_gallery/lib/gallery/backdrop.dart +++ b/dev/integration_tests/flutter_gallery/lib/gallery/backdrop.dart @@ -246,11 +246,13 @@ class _BackdropState extends State with SingleTickerProviderStateMixin } final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight; - _controller!.fling(velocity: switch (flingVelocity) { - < 0.0 => math.max(2.0, -flingVelocity), - > 0.0 => math.min(-2.0, -flingVelocity), - _ => _controller!.value < 0.5 ? -2.0 : 2.0, - }); + if (flingVelocity < 0.0) { + _controller!.fling(velocity: math.max(2.0, -flingVelocity)); + } else if (flingVelocity > 0.0) { + _controller!.fling(velocity: math.min(-2.0, -flingVelocity)); + } else { + _controller!.fling(velocity: _controller!.value < 0.5 ? -2.0 : 2.0); + } } void _toggleFrontLayer() { diff --git a/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart b/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart index fb38804d80..9dd635fdf9 100644 --- a/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart +++ b/dev/integration_tests/flutter_gallery/lib/gallery/syntax_highlighter.dart @@ -337,14 +337,22 @@ class _HighlightSpan { } TextStyle? textStyle(SyntaxHighlighterStyle? style) { - return switch (type) { - _HighlightType.number => style!.numberStyle, - _HighlightType.comment => style!.commentStyle, - _HighlightType.keyword => style!.keywordStyle, - _HighlightType.string => style!.stringStyle, - _HighlightType.punctuation => style!.punctuationStyle, - _HighlightType.klass => style!.classStyle, - _HighlightType.constant => style!.constantStyle, - }; + if (type == _HighlightType.number) { + return style!.numberStyle; + } else if (type == _HighlightType.comment) { + return style!.commentStyle; + } else if (type == _HighlightType.keyword) { + return style!.keywordStyle; + } else if (type == _HighlightType.string) { + return style!.stringStyle; + } else if (type == _HighlightType.punctuation) { + return style!.punctuationStyle; + } else if (type == _HighlightType.klass) { + return style!.classStyle; + } else if (type == _HighlightType.constant) { + return style!.constantStyle; + } else { + return style!.baseStyle; + } } } diff --git a/dev/integration_tests/new_gallery/lib/demos/material/cards_demo.dart b/dev/integration_tests/new_gallery/lib/demos/material/cards_demo.dart index 49714bbfb2..1bea3b337e 100644 --- a/dev/integration_tests/new_gallery/lib/demos/material/cards_demo.dart +++ b/dev/integration_tests/new_gallery/lib/demos/material/cards_demo.dart @@ -416,15 +416,20 @@ class _CardsDemoState extends State with RestorationMixin { for (final TravelDestination destination in destinations(context)) Container( margin: const EdgeInsets.only(bottom: 8), - child: switch (destination.cardType) { - CardType.standard => TravelDestinationItem(destination: destination), - CardType.tappable => TappableTravelDestinationItem(destination: destination), - CardType.selectable => SelectableTravelDestinationItem( - destination: destination, - isSelected: _isSelected.value, - onSelected: () => setState(() { _isSelected.value = !_isSelected.value; }), - ), - }, + child: (destination.cardType == CardType.standard) + ? TravelDestinationItem(destination: destination) + : destination.cardType == CardType.tappable + ? TappableTravelDestinationItem( + destination: destination) + : SelectableTravelDestinationItem( + destination: destination, + isSelected: _isSelected.value, + onSelected: () { + setState(() { + _isSelected.value = !_isSelected.value; + }); + }, + ), ), ], ), diff --git a/dev/integration_tests/new_gallery/lib/demos/reference/two_pane_demo.dart b/dev/integration_tests/new_gallery/lib/demos/reference/two_pane_demo.dart index 894479b2c5..c8956a427f 100644 --- a/dev/integration_tests/new_gallery/lib/demos/reference/two_pane_demo.dart +++ b/dev/integration_tests/new_gallery/lib/demos/reference/two_pane_demo.dart @@ -69,10 +69,13 @@ class TwoPaneDemoState extends State with RestorationMixin { ), endPane: DetailsPane( selectedIndex: _currentIndex.value, - onClose: switch (widget.type) { - TwoPaneDemoType.smallScreen => () => setState(() { _currentIndex.value = -1; }), - TwoPaneDemoType.foldable || TwoPaneDemoType.tablet => null, - }, + onClose: widget.type == TwoPaneDemoType.smallScreen + ? () { + setState(() { + _currentIndex.value = -1; + }); + } + : null, ), ), ); @@ -187,11 +190,11 @@ class SimulateScreen extends StatelessWidget { ), padding: const EdgeInsets.all(14), child: AspectRatio( - aspectRatio: switch (type) { - TwoPaneDemoType.foldable => foldableAspectRatio, - TwoPaneDemoType.tablet => tabletAspectRatio, - TwoPaneDemoType.smallScreen => singleScreenAspectRatio, - }, + aspectRatio: type == TwoPaneDemoType.foldable + ? foldableAspectRatio + : type == TwoPaneDemoType.tablet + ? tabletAspectRatio + : singleScreenAspectRatio, child: LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { final Size size = Size(constraints.maxWidth, constraints.maxHeight); final Size hingeSize = Size(size.width * hingeProportion, size.height); diff --git a/dev/integration_tests/new_gallery/lib/pages/settings_icon/icon.dart b/dev/integration_tests/new_gallery/lib/pages/settings_icon/icon.dart index ca4585875b..889f2b55dc 100644 --- a/dev/integration_tests/new_gallery/lib/pages/settings_icon/icon.dart +++ b/dev/integration_tests/new_gallery/lib/pages/settings_icon/icon.dart @@ -34,12 +34,12 @@ class _SettingsIconPainter extends CustomPainter { /// /// The icon is aligned to the bottom-start corner. void _computeCenterAndScaling(Size size) { - final double dx = switch (Directionality.of(context)) { - TextDirection.rtl => size.width - unitWidth * _scaling / 2, - TextDirection.ltr => unitWidth * _scaling / 2, - }; - _center = Offset(dx, size.height - unitHeight * _scaling / 2); _scaling = min(size.width / unitWidth, size.height / unitHeight); + _center = Directionality.of(context) == TextDirection.ltr + ? Offset( + unitWidth * _scaling / 2, size.height - unitHeight * _scaling / 2) + : Offset(size.width - unitWidth * _scaling / 2, + size.height - unitHeight * _scaling / 2); } /// Transforms an offset in relative units into an offset in logical pixels. diff --git a/dev/integration_tests/wide_gamut_test/integration_test/app_test.dart b/dev/integration_tests/wide_gamut_test/integration_test/app_test.dart index 10d615b9a2..834a54b06b 100644 --- a/dev/integration_tests/wide_gamut_test/integration_test/app_test.dart +++ b/dev/integration_tests/wide_gamut_test/integration_test/app_test.dart @@ -103,16 +103,21 @@ bool _findBGR10Color( return foundDeepRed; } -bool _findColor(List result, List color) { +bool _findColor(List result, List color) { expect(result, isNotNull); expect(result.length, 4); - final [int width, int height, String format, Uint8List bytes] = result; - return switch (format) { - 'MTLPixelFormatBGR10_XR' => _findBGR10Color(bytes, width, height, color), - 'MTLPixelFormatBGRA10_XR' => _findBGRA10Color(bytes, width, height, color), - 'MTLPixelFormatRGBA16Float' => _findRGBAF16Color(bytes, width, height, color), - _ => fail('Unsupported pixel format: $format'), - }; + final int width = (result[0] as int?)!; + final int height = (result[1] as int?)!; + final String format = (result[2] as String?)!; + if (format == 'MTLPixelFormatBGR10_XR') { + return _findBGR10Color((result[3] as Uint8List?)!, width, height, color); + } else if (format == 'MTLPixelFormatBGRA10_XR') { + return _findBGRA10Color((result[3] as Uint8List?)!, width, height, color); + } else if (format == 'MTLPixelFormatRGBA16Float') { + return _findRGBAF16Color((result[3] as Uint8List?)!, width, height, color); + } else { + fail('Unsupported pixel format: $format'); + } } void main() { diff --git a/dev/manual_tests/lib/density.dart b/dev/manual_tests/lib/density.dart index 4bf85dc6d9..801ac9c309 100644 --- a/dev/manual_tests/lib/density.dart +++ b/dev/manual_tests/lib/density.dart @@ -163,12 +163,14 @@ class _OptionsState extends State { double sliderValue = 0.0; String _densityToProfile(VisualDensity density) { - return switch (density) { - VisualDensity.standard => 'standard', - VisualDensity.compact => 'compact', - VisualDensity.comfortable => 'comfortable', - _ => 'custom', - }; + if (density == VisualDensity.standard) { + return 'standard'; + } else if (density == VisualDensity.compact) { + return 'compact'; + } else if (density == VisualDensity.comfortable) { + return 'comfortable'; + } + return 'custom'; } VisualDensity _profileToDensity(String? profile) { diff --git a/dev/manual_tests/lib/page_view.dart b/dev/manual_tests/lib/page_view.dart index a790ca146d..25b9a79d4c 100644 --- a/dev/manual_tests/lib/page_view.dart +++ b/dev/manual_tests/lib/page_view.dart @@ -70,7 +70,9 @@ class PageViewAppState extends State { void switchScrollDirection() { setState(() { - scrollDirection = flipAxis(scrollDirection); + scrollDirection = (scrollDirection == Axis.vertical) + ? Axis.horizontal + : Axis.vertical; }); } @@ -111,7 +113,9 @@ class PageViewAppState extends State { AppBar _buildAppBar() { return AppBar( title: const Text('PageView'), - actions: [Text(scrollDirection.name)], + actions: [ + Text(scrollDirection == Axis.horizontal ? 'horizontal' : 'vertical'), + ], ); } diff --git a/dev/tools/gen_defaults/lib/template.dart b/dev/tools/gen_defaults/lib/template.dart index a46f1c165c..1e611feb98 100644 --- a/dev/tools/gen_defaults/lib/template.dart +++ b/dev/tools/gen_defaults/lib/template.dart @@ -169,13 +169,16 @@ abstract class TokenTemplate { } String? _numToString(Object? value, [int? digits]) { - return switch (value) { - null => null, - double.infinity => 'double.infinity', - num() when digits == null => value.toString(), - num() => value.toStringAsFixed(digits!), - _ => getToken(value as String).toString(), - }; + if (value == null) { + return null; + } + if (value is num) { + if (value == double.infinity) { + return 'double.infinity'; + } + return digits == null ? value.toString() : value.toStringAsFixed(digits); + } + return getToken(value as String).toString(); } /// Generate an elevation value for the given component token. diff --git a/dev/tools/gen_keycodes/lib/utils.dart b/dev/tools/gen_keycodes/lib/utils.dart index 8a94ea182c..802dd69ff8 100644 --- a/dev/tools/gen_keycodes/lib/utils.dart +++ b/dev/tools/gen_keycodes/lib/utils.dart @@ -205,11 +205,18 @@ Map reverseMapOfListOfString(Map> inMap, vo /// /// Will modify the input map. Map removeEmptyValues(Map map) { - return map..removeWhere((String key, dynamic value) => switch (value) { - null => true, - Map() => removeEmptyValues(value).isEmpty, - Iterable() => value.isEmpty, - _ => false, + return map..removeWhere((String key, dynamic value) { + if (value == null) { + return true; + } + if (value is Map) { + final Map regularizedMap = removeEmptyValues(value); + return regularizedMap.isEmpty; + } + if (value is Iterable) { + return value.isEmpty; + } + return false; }); } diff --git a/examples/api/lib/material/snack_bar/snack_bar.2.dart b/examples/api/lib/material/snack_bar/snack_bar.2.dart index 3ad1d7f63c..63fca4d7f9 100644 --- a/examples/api/lib/material/snack_bar/snack_bar.2.dart +++ b/examples/api/lib/material/snack_bar/snack_bar.2.dart @@ -123,10 +123,13 @@ class _SnackBarExampleState extends State { const Text('Multi Line Text'), Switch( value: _multiLine, - onChanged: switch (_snackBarBehavior) { - SnackBarBehavior.fixed || null => null, - SnackBarBehavior.floating => (bool value) => setState(() { _multiLine = !_multiLine; }), - }, + onChanged: _snackBarBehavior == SnackBarBehavior.fixed + ? null + : (bool value) { + setState(() { + _multiLine = !_multiLine; + }); + }, ), ], ), @@ -136,10 +139,13 @@ class _SnackBarExampleState extends State { value: _sliderValue, divisions: 20, label: _sliderValue.toStringAsFixed(2), - onChanged: switch (_snackBarBehavior) { - SnackBarBehavior.fixed || null => null, - SnackBarBehavior.floating => (double value) => setState(() { _sliderValue = value; }), - }, + onChanged: _snackBarBehavior == SnackBarBehavior.fixed + ? null + : (double value) { + setState(() { + _sliderValue = value; + }); + }, ), ]), const SizedBox(height: 16.0), diff --git a/packages/flutter/test/widgets/linked_scroll_view_test.dart b/packages/flutter/test/widgets/linked_scroll_view_test.dart index 86ce637010..ee2a5c5921 100644 --- a/packages/flutter/test/widgets/linked_scroll_view_test.dart +++ b/packages/flutter/test/widgets/linked_scroll_view_test.dart @@ -91,14 +91,17 @@ class LinkedScrollController extends ScrollController { @override void debugFillDescription(List description) { super.debugFillDescription(description); - final String linkSymbol = switch ((before, after)) { - (null, null) => 'none', - (null, _) => '➡', - (_, null) => '⬅', - (_, _) => '⬌', - }; - description.add('links: $linkSymbol'); + if (before != null && after != null) { + description.add('links: ⬌'); + } else if (before != null) { + description.add('links: ⬅'); + } else if (after != null) { + description.add('links: ➡'); + } else { + description.add('links: none'); + } } + } class LinkedScrollPosition extends ScrollPositionWithSingleContext { diff --git a/packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart b/packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart index 5e5b74623f..34a7f3ea45 100644 --- a/packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart +++ b/packages/flutter/test/widgets/overscroll_stretch_indicator_test.dart @@ -27,10 +27,11 @@ void main() { final AxisDirection axisDirection; switch (axis) { case Axis.horizontal: - axisDirection = switch (textDirection) { - TextDirection.rtl => reverse ? AxisDirection.right : AxisDirection.left, - TextDirection.ltr => reverse ? AxisDirection.left : AxisDirection.right, - }; + if (textDirection == TextDirection.rtl) { + axisDirection = reverse ? AxisDirection.right : AxisDirection.left; + } else { + axisDirection = reverse ? AxisDirection.left : AxisDirection.right; + } case Axis.vertical: axisDirection = reverse ? AxisDirection.up : AxisDirection.down; } diff --git a/packages/flutter/test/widgets/two_dimensional_viewport_test.dart b/packages/flutter/test/widgets/two_dimensional_viewport_test.dart index 3aec287749..a3caa62125 100644 --- a/packages/flutter/test/widgets/two_dimensional_viewport_test.dart +++ b/packages/flutter/test/widgets/two_dimensional_viewport_test.dart @@ -2722,11 +2722,13 @@ void main() { addAutomaticKeepAlives: false, addRepaintBoundaries: false, builder: (BuildContext context, ChildVicinity vicinity) { - final ValueKey? key = switch (vicinity) { - ChildVicinity(xIndex: 1, yIndex: 1) => const ValueKey(1), - ChildVicinity(xIndex: 1, yIndex: 2) => const ValueKey(2), - _ => null, - }; + ValueKey? key; + if (vicinity == const ChildVicinity(xIndex: 1, yIndex: 1)) { + key = const ValueKey(1); + } else if (vicinity == + const ChildVicinity(xIndex: 1, yIndex: 2)) { + key = const ValueKey(2); + } return SizedBox.square(key: key, dimension: 200); }); final TwoDimensionalChildBuilderDelegate delegate2 = @@ -2768,11 +2770,13 @@ void main() { addAutomaticKeepAlives: false, addRepaintBoundaries: false, builder: (BuildContext context, ChildVicinity vicinity) { - final ValueKey? key = switch (vicinity) { - ChildVicinity(xIndex: 0, yIndex: 0) => const ValueKey(1), - ChildVicinity(xIndex: 1, yIndex: 1) => const ValueKey(2), - _ => null, - }; + ValueKey? key; + if (vicinity == const ChildVicinity(xIndex: 1, yIndex: 1)) { + key = const ValueKey(1); + } else if (vicinity == + const ChildVicinity(xIndex: 1, yIndex: 2)) { + key = const ValueKey(2); + } return Checkbox(key: key, value: false, onChanged: (_) {}); }); final TwoDimensionalChildBuilderDelegate delegate2 = diff --git a/packages/flutter_driver/lib/src/driver/timeline.dart b/packages/flutter_driver/lib/src/driver/timeline.dart index 16d2a62cf7..bda77b3a61 100644 --- a/packages/flutter_driver/lib/src/driver/timeline.dart +++ b/packages/flutter_driver/lib/src/driver/timeline.dart @@ -118,12 +118,19 @@ List? _parseEvents(Map json) { .toList(); timelineEvents.sort((TimelineEvent e1, TimelineEvent e2) { - return switch ((e1.timestampMicros, e2.timestampMicros)) { - (null, null) => 0, - (_, null) => 1, - (null, _) => -1, - (final int ts1, final int ts2) => ts1.compareTo(ts2), - }; + final int? ts1 = e1.timestampMicros; + final int? ts2 = e2.timestampMicros; + if (ts1 == null) { + if (ts2 == null) { + return 0; + } else { + return -1; + } + } else if (ts2 == null) { + return 1; + } else { + return ts1.compareTo(ts2); + } }); return timelineEvents; diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index 6e955a4fdb..500d658915 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -546,11 +546,12 @@ Matcher coversSameAreaAs(Path expectedPath, { required Rect areaToCompare, int s /// * [flutter_test] for a discussion of test configurations, whereby callers /// may swap out the backend for this matcher. AsyncMatcher matchesGoldenFile(Object key, {int? version}) { - return switch (key) { - Uri() => MatchesGoldenFile(key, version), - String() => MatchesGoldenFile.forStringPath(key, version), - _ => throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'), - }; + if (key is Uri) { + return MatchesGoldenFile(key, version); + } else if (key is String) { + return MatchesGoldenFile.forStringPath(key, version); + } + throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'); } /// Asserts that a [Finder], [Future], or [ui.Image] matches a diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 74e3b196e5..032c1d894c 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -932,11 +932,14 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker final Key? key = widget.key; if (key is ValueKey) { - final String? keyLabel = switch (key.value) { - int() || double() || bool() => 'const ${key.runtimeType}(${key.value})', - final String value => "const Key('$value')", - _ => null, - }; + String? keyLabel; + if (key is ValueKey || + key is ValueKey || + key is ValueKey) { + keyLabel = 'const ${key.runtimeType}(${key.value})'; + } else if (key is ValueKey) { + keyLabel = "const Key('${key.value}')"; + } if (keyLabel != null) { final Iterable matches = find.byKey(key).evaluate(); if (matches.length == 1) { diff --git a/packages/flutter_tools/lib/src/android/deferred_components_validator.dart b/packages/flutter_tools/lib/src/android/deferred_components_validator.dart index edb862e6e8..f22a40240a 100644 --- a/packages/flutter_tools/lib/src/android/deferred_components_validator.dart +++ b/packages/flutter_tools/lib/src/android/deferred_components_validator.dart @@ -131,11 +131,12 @@ abstract class DeferredComponentsValidator { if (line.startsWith('Only in android')) { continue; } - final TerminalColor color = switch (line[0]) { - '+' => TerminalColor.green, - '-' => TerminalColor.red, - _ => TerminalColor.grey, - }; + TerminalColor color = TerminalColor.grey; + if (line.startsWith('+')) { + color = TerminalColor.green; + } else if (line.startsWith('-')) { + color = TerminalColor.red; + } logger.printStatus(line, color: color); } logger.printStatus(''); diff --git a/packages/flutter_tools/lib/src/base/multi_root_file_system.dart b/packages/flutter_tools/lib/src/base/multi_root_file_system.dart index b79c135088..f718478c2b 100644 --- a/packages/flutter_tools/lib/src/base/multi_root_file_system.dart +++ b/packages/flutter_tools/lib/src/base/multi_root_file_system.dart @@ -115,15 +115,18 @@ class MultiRootFileSystem extends ForwardingFileSystem { /// If the path is a multiroot uri, resolve to the actual path of the /// underlying file system. Otherwise, return as is. dynamic _resolve(dynamic path) { + Uri uri; if (path == null) { return null; + } else if (path is String) { + uri = Uri.parse(path); + } else if (path is Uri) { + uri = path; + } else if (path is FileSystemEntity) { + uri = path.uri; + } else { + throw ArgumentError('Invalid type for "path": ${(path as Object?)?.runtimeType}'); } - final Uri uri = switch (path) { - String() => Uri.parse(path), - Uri() => path, - FileSystemEntity() => path.uri, - _ => throw ArgumentError('Invalid type for "path": ${(path as Object?)?.runtimeType}'), - }; if (!uri.hasScheme || uri.scheme != _scheme) { return path; diff --git a/packages/flutter_tools/lib/src/commands/build_ios.dart b/packages/flutter_tools/lib/src/commands/build_ios.dart index 25eaf1156b..9530e58033 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios.dart @@ -666,10 +666,11 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand { final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device'; final String typeName = globals.artifacts!.getEngineType(TargetPlatform.ios, buildInfo.mode); - globals.printStatus(switch (xcodeBuildAction) { - XcodeBuildAction.build => 'Building $app for $logTarget ($typeName)...', - XcodeBuildAction.archive => 'Archiving $app...', - }); + if (xcodeBuildAction == XcodeBuildAction.build) { + globals.printStatus('Building $app for $logTarget ($typeName)...'); + } else { + globals.printStatus('Archiving $app...'); + } final XcodeBuildResult result = await buildXcodeProject( app: app, buildInfo: buildInfo, diff --git a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart index ee657338c8..12f122745c 100644 --- a/packages/flutter_tools/lib/src/commands/build_ios_framework.dart +++ b/packages/flutter_tools/lib/src/commands/build_ios_framework.dart @@ -429,17 +429,22 @@ end Directory simulatorBuildOutput, ) async { const String appFrameworkName = 'App.framework'; + final Status status = globals.logger.startProgress( ' ├─Building App.xcframework...', ); + final List environmentTypes = [ + EnvironmentType.physical, + EnvironmentType.simulator, + ]; final List frameworks = []; try { - for (final EnvironmentType sdkType in EnvironmentType.values) { - final Directory outputBuildDirectory = switch (sdkType) { - EnvironmentType.physical => iPhoneBuildOutput, - EnvironmentType.simulator => simulatorBuildOutput, - }; + for (final EnvironmentType sdkType in environmentTypes) { + final Directory outputBuildDirectory = + sdkType == EnvironmentType.physical + ? iPhoneBuildOutput + : simulatorBuildOutput; frameworks.add(outputBuildDirectory.childDirectory(appFrameworkName)); final Environment environment = Environment( projectDir: globals.fs.currentDirectory, diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index d94ad567c1..e020b11f37 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -1429,12 +1429,16 @@ Map _operationResultToMap(OperationResult result) { } Object? _toJsonable(Object? obj) { - return switch (obj) { - String() || int() || bool() || Map() || List() || null => obj, - OperationResult() => _operationResultToMap(obj), - ToolExit() => obj.message, - _ => obj.toString(), - }; + if (obj is String || obj is int || obj is bool || obj is Map || obj is List || obj == null) { + return obj; + } + if (obj is OperationResult) { + return _operationResultToMap(obj); + } + if (obj is ToolExit) { + return obj.message; + } + return '$obj'; } class NotifyingLogger extends DelegatingLogger { diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index 819df78a39..6afabbd5d0 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -942,11 +942,12 @@ enum ImpellerStatus { const ImpellerStatus._(this.asBool); - factory ImpellerStatus.fromBool(bool? b) => switch (b) { - true => enabled, - false => disabled, - null => platformDefault, - }; + factory ImpellerStatus.fromBool(bool? b) { + if (b == null) { + return platformDefault; + } + return b ? enabled : disabled; + } final bool? asBool; } diff --git a/packages/flutter_tools/lib/src/ios/core_devices.dart b/packages/flutter_tools/lib/src/ios/core_devices.dart index adc6eddfe6..729f06e084 100644 --- a/packages/flutter_tools/lib/src/ios/core_devices.dart +++ b/packages/flutter_tools/lib/src/ios/core_devices.dart @@ -439,11 +439,15 @@ class IOSCoreDevice { String? get udid => hardwareProperties?.udid; DeviceConnectionInterface? get connectionInterface { - return switch (connectionProperties?.transportType?.toLowerCase()) { - 'localnetwork' => DeviceConnectionInterface.wireless, - 'wired' => DeviceConnectionInterface.attached, - _ => null, - }; + final String? transportType = connectionProperties?.transportType; + if (transportType != null) { + if (transportType.toLowerCase() == 'localnetwork') { + return DeviceConnectionInterface.wireless; + } else if (transportType.toLowerCase() == 'wired') { + return DeviceConnectionInterface.attached; + } + } + return null; } @visibleForTesting diff --git a/packages/flutter_tools/lib/src/localizations/message_parser.dart b/packages/flutter_tools/lib/src/localizations/message_parser.dart index 99b45301f3..6591d9da23 100644 --- a/packages/flutter_tools/lib/src/localizations/message_parser.dart +++ b/packages/flutter_tools/lib/src/localizations/message_parser.dart @@ -96,12 +96,16 @@ class Node { // Token constructors. Node.openBrace(this.positionInMessage): type = ST.openBrace, value = '{'; Node.closeBrace(this.positionInMessage): type = ST.closeBrace, value = '}'; - Node.brace(this.positionInMessage, String this.value) - : type = switch (value) { - '{' => ST.openBrace, - '}' => ST.closeBrace, - _ => throw L10nException('Provided value $value is not a brace.') - }; + Node.brace(this.positionInMessage, String this.value) { + if (value == '{') { + type = ST.openBrace; + } else if (value == '}') { + type = ST.closeBrace; + } else { + // We should never arrive here. + throw L10nException('Provided value $value is not a brace.'); + } + } Node.equalSign(this.positionInMessage): type = ST.equalSign, value = '='; Node.comma(this.positionInMessage): type = ST.comma, value = ','; Node.string(this.positionInMessage, String this.value): type = ST.string; diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index d24037b96b..225ca7bf47 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -914,10 +914,12 @@ abstract class ResidentHandlers { final Brightness? current = await flutterDevices.first!.vmService!.flutterBrightnessOverride( isolateId: views.first.uiIsolate!.id!, ); - final Brightness next = switch (current) { - Brightness.light => Brightness.dark, - Brightness.dark || null => Brightness.light, - }; + Brightness next; + if (current == Brightness.light) { + next = Brightness.dark; + } else { + next = Brightness.light; + } for (final FlutterDevice? device in flutterDevices) { final List views = await device!.vmService!.getFlutterViews(); for (final FlutterView view in views) { diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart index 54671c0605..87f2f0e40d 100644 --- a/packages/flutter_tools/lib/src/runner/flutter_command.dart +++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart @@ -772,14 +772,15 @@ abstract class FlutterCommand extends Command { return null; }(); - DeviceConnectionInterface? get deviceConnectionInterface { + DeviceConnectionInterface? get deviceConnectionInterface { if ((argResults?.options.contains(FlutterOptions.kDeviceConnection) ?? false) && (argResults?.wasParsed(FlutterOptions.kDeviceConnection) ?? false)) { - return switch (stringArg(FlutterOptions.kDeviceConnection)) { - 'attached' => DeviceConnectionInterface.attached, - 'wireless' => DeviceConnectionInterface.wireless, - _ => null, - }; + final String? connectionType = stringArg(FlutterOptions.kDeviceConnection); + if (connectionType == 'attached') { + return DeviceConnectionInterface.attached; + } else if (connectionType == 'wireless') { + return DeviceConnectionInterface.wireless; + } } return null; } diff --git a/packages/flutter_tools/test/src/context.dart b/packages/flutter_tools/test/src/context.dart index a4b3c7161f..7a7caf8c01 100644 --- a/packages/flutter_tools/test/src/context.dart +++ b/packages/flutter_tools/test/src/context.dart @@ -290,11 +290,13 @@ class FakeDeviceManager implements DeviceManager { Device? getSingleEphemeralDevice(List devices) => null; List filteredDevices(DeviceDiscoveryFilter? filter) { - return switch (filter?.deviceConnectionInterface) { - DeviceConnectionInterface.attached => attachedDevices, - DeviceConnectionInterface.wireless => wirelessDevices, - null => attachedDevices + wirelessDevices, - }; + if (filter?.deviceConnectionInterface == DeviceConnectionInterface.attached) { + return attachedDevices; + } + if (filter?.deviceConnectionInterface == DeviceConnectionInterface.wireless) { + return wirelessDevices; + } + return attachedDevices + wirelessDevices; } }