mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
if
chains → switch
expressions (#147793)
Previous "if-chains" pull requests: - https://github.com/flutter/flutter/pull/144905 - https://github.com/flutter/flutter/pull/144977 - https://github.com/flutter/flutter/pull/145194 - https://github.com/flutter/flutter/pull/146293 - https://github.com/flutter/flutter/pull/147472 <br> I think this one should be enough to wrap things up! fixes https://github.com/flutter/flutter/issues/144903 --------- Co-authored-by: Victor Sanni <victorsanniay@gmail.com>
This commit is contained in:
parent
c90e18c6f5
commit
4734d80f22
@ -209,13 +209,11 @@ class ListItem extends StatelessWidget {
|
||||
}
|
||||
|
||||
String _convertCountToStr(int count) {
|
||||
if (count < 10000) {
|
||||
return count.toString();
|
||||
} else if (count < 100000) {
|
||||
return '${(count / 10000).toStringAsPrecision(2)}w';
|
||||
} else {
|
||||
return '${(count / 10000).floor()}w';
|
||||
}
|
||||
return switch (count) {
|
||||
< 10000 => count.toString(),
|
||||
< 100000 => '${(count / 10000).toStringAsPrecision(2)}w',
|
||||
_ => '${(count / 10000).floor()}w',
|
||||
};
|
||||
}
|
||||
|
||||
Widget _buildUserInfo() {
|
||||
|
@ -31,13 +31,11 @@ class BenchBuildMaterialCheckbox extends WidgetBuildRecorder {
|
||||
}
|
||||
|
||||
Row _buildRow() {
|
||||
if (_isChecked == null) {
|
||||
_isChecked = true;
|
||||
} else if (_isChecked!) {
|
||||
_isChecked = false;
|
||||
} else {
|
||||
_isChecked = null;
|
||||
}
|
||||
_isChecked = switch (_isChecked) {
|
||||
null => true,
|
||||
true => false,
|
||||
false => null,
|
||||
};
|
||||
|
||||
return Row(
|
||||
children: List<Widget>.generate(10, (int i) {
|
||||
|
@ -255,16 +255,14 @@ class StartContext extends Context {
|
||||
if (atBranchPoint) {
|
||||
return ReleaseType.BETA_INITIAL;
|
||||
}
|
||||
|
||||
if (releaseChannel == 'stable') {
|
||||
if (lastVersion.type == VersionType.stable) {
|
||||
return ReleaseType.STABLE_HOTFIX;
|
||||
} else {
|
||||
return ReleaseType.STABLE_INITIAL;
|
||||
}
|
||||
if (releaseChannel != 'stable') {
|
||||
return ReleaseType.BETA_HOTFIX;
|
||||
}
|
||||
|
||||
return ReleaseType.BETA_HOTFIX;
|
||||
return switch (lastVersion.type) {
|
||||
VersionType.stable => ReleaseType.STABLE_HOTFIX,
|
||||
VersionType.development || VersionType.gitDescribe || VersionType.latest => ReleaseType.STABLE_INITIAL,
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> run() async {
|
||||
|
@ -307,13 +307,11 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
|
||||
}
|
||||
|
||||
final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight;
|
||||
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);
|
||||
}
|
||||
_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,
|
||||
});
|
||||
}
|
||||
|
||||
// Stacks a BackdropPanel, which displays the selected category, on top
|
||||
|
@ -184,21 +184,18 @@ class _ListDemoState extends State<ListDemo> {
|
||||
}
|
||||
|
||||
Widget buildListTile(BuildContext context, String item) {
|
||||
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.',
|
||||
);
|
||||
}
|
||||
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.',
|
||||
};
|
||||
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: secondary,
|
||||
subtitle: subtitle != null ? Text(subtitle) : null,
|
||||
trailing: _showIcons != null ? Icon(Icons.info, color: Theme.of(context).disabledColor) : null,
|
||||
),
|
||||
);
|
||||
|
@ -246,13 +246,11 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
|
||||
}
|
||||
|
||||
final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight;
|
||||
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);
|
||||
}
|
||||
_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,
|
||||
});
|
||||
}
|
||||
|
||||
void _toggleFrontLayer() {
|
||||
|
@ -337,22 +337,14 @@ class _HighlightSpan {
|
||||
}
|
||||
|
||||
TextStyle? textStyle(SyntaxHighlighterStyle? style) {
|
||||
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;
|
||||
}
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -416,20 +416,15 @@ class _CardsDemoState extends State<CardsDemo> with RestorationMixin {
|
||||
for (final TravelDestination destination in destinations(context))
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
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;
|
||||
});
|
||||
},
|
||||
),
|
||||
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; }),
|
||||
),
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -69,13 +69,10 @@ class TwoPaneDemoState extends State<TwoPaneDemo> with RestorationMixin {
|
||||
),
|
||||
endPane: DetailsPane(
|
||||
selectedIndex: _currentIndex.value,
|
||||
onClose: widget.type == TwoPaneDemoType.smallScreen
|
||||
? () {
|
||||
setState(() {
|
||||
_currentIndex.value = -1;
|
||||
});
|
||||
}
|
||||
: null,
|
||||
onClose: switch (widget.type) {
|
||||
TwoPaneDemoType.smallScreen => () => setState(() { _currentIndex.value = -1; }),
|
||||
TwoPaneDemoType.foldable || TwoPaneDemoType.tablet => null,
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -190,11 +187,11 @@ class SimulateScreen extends StatelessWidget {
|
||||
),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: AspectRatio(
|
||||
aspectRatio: type == TwoPaneDemoType.foldable
|
||||
? foldableAspectRatio
|
||||
: type == TwoPaneDemoType.tablet
|
||||
? tabletAspectRatio
|
||||
: singleScreenAspectRatio,
|
||||
aspectRatio: switch (type) {
|
||||
TwoPaneDemoType.foldable => foldableAspectRatio,
|
||||
TwoPaneDemoType.tablet => tabletAspectRatio,
|
||||
TwoPaneDemoType.smallScreen => 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);
|
||||
|
@ -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.
|
||||
|
@ -103,21 +103,16 @@ bool _findBGR10Color(
|
||||
return foundDeepRed;
|
||||
}
|
||||
|
||||
bool _findColor(List<Object?> result, List<double> color) {
|
||||
bool _findColor(List<dynamic> result, List<double> color) {
|
||||
expect(result, isNotNull);
|
||||
expect(result.length, 4);
|
||||
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');
|
||||
}
|
||||
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'),
|
||||
};
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -163,14 +163,12 @@ class _OptionsState extends State<Options> {
|
||||
double sliderValue = 0.0;
|
||||
|
||||
String _densityToProfile(VisualDensity density) {
|
||||
if (density == VisualDensity.standard) {
|
||||
return 'standard';
|
||||
} else if (density == VisualDensity.compact) {
|
||||
return 'compact';
|
||||
} else if (density == VisualDensity.comfortable) {
|
||||
return 'comfortable';
|
||||
}
|
||||
return 'custom';
|
||||
return switch (density) {
|
||||
VisualDensity.standard => 'standard',
|
||||
VisualDensity.compact => 'compact',
|
||||
VisualDensity.comfortable => 'comfortable',
|
||||
_ => 'custom',
|
||||
};
|
||||
}
|
||||
|
||||
VisualDensity _profileToDensity(String? profile) {
|
||||
|
@ -70,9 +70,7 @@ class PageViewAppState extends State<PageViewApp> {
|
||||
|
||||
void switchScrollDirection() {
|
||||
setState(() {
|
||||
scrollDirection = (scrollDirection == Axis.vertical)
|
||||
? Axis.horizontal
|
||||
: Axis.vertical;
|
||||
scrollDirection = flipAxis(scrollDirection);
|
||||
});
|
||||
}
|
||||
|
||||
@ -113,9 +111,7 @@ class PageViewAppState extends State<PageViewApp> {
|
||||
AppBar _buildAppBar() {
|
||||
return AppBar(
|
||||
title: const Text('PageView'),
|
||||
actions: <Widget>[
|
||||
Text(scrollDirection == Axis.horizontal ? 'horizontal' : 'vertical'),
|
||||
],
|
||||
actions: <Widget>[Text(scrollDirection.name)],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -169,16 +169,13 @@ abstract class TokenTemplate {
|
||||
}
|
||||
|
||||
String? _numToString(Object? value, [int? digits]) {
|
||||
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();
|
||||
return switch (value) {
|
||||
null => null,
|
||||
double.infinity => 'double.infinity',
|
||||
num() when digits == null => value.toString(),
|
||||
num() => value.toStringAsFixed(digits!),
|
||||
_ => getToken(value as String).toString(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Generate an elevation value for the given component token.
|
||||
|
@ -205,18 +205,11 @@ Map<String, String> reverseMapOfListOfString(Map<String, List<String>> inMap, vo
|
||||
///
|
||||
/// Will modify the input map.
|
||||
Map<String, dynamic> removeEmptyValues(Map<String, dynamic> map) {
|
||||
return map..removeWhere((String key, dynamic value) {
|
||||
if (value == null) {
|
||||
return true;
|
||||
}
|
||||
if (value is Map<String, dynamic>) {
|
||||
final Map<String, dynamic> regularizedMap = removeEmptyValues(value);
|
||||
return regularizedMap.isEmpty;
|
||||
}
|
||||
if (value is Iterable<dynamic>) {
|
||||
return value.isEmpty;
|
||||
}
|
||||
return false;
|
||||
return map..removeWhere((String key, dynamic value) => switch (value) {
|
||||
null => true,
|
||||
Map<String, dynamic>() => removeEmptyValues(value).isEmpty,
|
||||
Iterable<dynamic>() => value.isEmpty,
|
||||
_ => false,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -123,13 +123,10 @@ class _SnackBarExampleState extends State<SnackBarExample> {
|
||||
const Text('Multi Line Text'),
|
||||
Switch(
|
||||
value: _multiLine,
|
||||
onChanged: _snackBarBehavior == SnackBarBehavior.fixed
|
||||
? null
|
||||
: (bool value) {
|
||||
setState(() {
|
||||
_multiLine = !_multiLine;
|
||||
});
|
||||
},
|
||||
onChanged: switch (_snackBarBehavior) {
|
||||
SnackBarBehavior.fixed || null => null,
|
||||
SnackBarBehavior.floating => (bool value) => setState(() { _multiLine = !_multiLine; }),
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -139,13 +136,10 @@ class _SnackBarExampleState extends State<SnackBarExample> {
|
||||
value: _sliderValue,
|
||||
divisions: 20,
|
||||
label: _sliderValue.toStringAsFixed(2),
|
||||
onChanged: _snackBarBehavior == SnackBarBehavior.fixed
|
||||
? null
|
||||
: (double value) {
|
||||
setState(() {
|
||||
_sliderValue = value;
|
||||
});
|
||||
},
|
||||
onChanged: switch (_snackBarBehavior) {
|
||||
SnackBarBehavior.fixed || null => null,
|
||||
SnackBarBehavior.floating => (double value) => setState(() { _sliderValue = value; }),
|
||||
},
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 16.0),
|
||||
|
@ -91,17 +91,14 @@ class LinkedScrollController extends ScrollController {
|
||||
@override
|
||||
void debugFillDescription(List<String> description) {
|
||||
super.debugFillDescription(description);
|
||||
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');
|
||||
}
|
||||
final String linkSymbol = switch ((before, after)) {
|
||||
(null, null) => 'none',
|
||||
(null, _) => '➡',
|
||||
(_, null) => '⬅',
|
||||
(_, _) => '⬌',
|
||||
};
|
||||
description.add('links: $linkSymbol');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LinkedScrollPosition extends ScrollPositionWithSingleContext {
|
||||
|
@ -27,11 +27,10 @@ void main() {
|
||||
final AxisDirection axisDirection;
|
||||
switch (axis) {
|
||||
case Axis.horizontal:
|
||||
if (textDirection == TextDirection.rtl) {
|
||||
axisDirection = reverse ? AxisDirection.right : AxisDirection.left;
|
||||
} else {
|
||||
axisDirection = reverse ? AxisDirection.left : AxisDirection.right;
|
||||
}
|
||||
axisDirection = switch (textDirection) {
|
||||
TextDirection.rtl => reverse ? AxisDirection.right : AxisDirection.left,
|
||||
TextDirection.ltr => reverse ? AxisDirection.left : AxisDirection.right,
|
||||
};
|
||||
case Axis.vertical:
|
||||
axisDirection = reverse ? AxisDirection.up : AxisDirection.down;
|
||||
}
|
||||
|
@ -2722,13 +2722,11 @@ void main() {
|
||||
addAutomaticKeepAlives: false,
|
||||
addRepaintBoundaries: false,
|
||||
builder: (BuildContext context, ChildVicinity vicinity) {
|
||||
ValueKey<int>? key;
|
||||
if (vicinity == const ChildVicinity(xIndex: 1, yIndex: 1)) {
|
||||
key = const ValueKey<int>(1);
|
||||
} else if (vicinity ==
|
||||
const ChildVicinity(xIndex: 1, yIndex: 2)) {
|
||||
key = const ValueKey<int>(2);
|
||||
}
|
||||
final ValueKey<int>? key = switch (vicinity) {
|
||||
ChildVicinity(xIndex: 1, yIndex: 1) => const ValueKey<int>(1),
|
||||
ChildVicinity(xIndex: 1, yIndex: 2) => const ValueKey<int>(2),
|
||||
_ => null,
|
||||
};
|
||||
return SizedBox.square(key: key, dimension: 200);
|
||||
});
|
||||
final TwoDimensionalChildBuilderDelegate delegate2 =
|
||||
@ -2770,13 +2768,11 @@ void main() {
|
||||
addAutomaticKeepAlives: false,
|
||||
addRepaintBoundaries: false,
|
||||
builder: (BuildContext context, ChildVicinity vicinity) {
|
||||
ValueKey<int>? key;
|
||||
if (vicinity == const ChildVicinity(xIndex: 1, yIndex: 1)) {
|
||||
key = const ValueKey<int>(1);
|
||||
} else if (vicinity ==
|
||||
const ChildVicinity(xIndex: 1, yIndex: 2)) {
|
||||
key = const ValueKey<int>(2);
|
||||
}
|
||||
final ValueKey<int>? key = switch (vicinity) {
|
||||
ChildVicinity(xIndex: 0, yIndex: 0) => const ValueKey<int>(1),
|
||||
ChildVicinity(xIndex: 1, yIndex: 1) => const ValueKey<int>(2),
|
||||
_ => null,
|
||||
};
|
||||
return Checkbox(key: key, value: false, onChanged: (_) {});
|
||||
});
|
||||
final TwoDimensionalChildBuilderDelegate delegate2 =
|
||||
|
@ -118,19 +118,12 @@ List<TimelineEvent>? _parseEvents(Map<String, dynamic> json) {
|
||||
.toList();
|
||||
|
||||
timelineEvents.sort((TimelineEvent e1, TimelineEvent e2) {
|
||||
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 switch ((e1.timestampMicros, e2.timestampMicros)) {
|
||||
(null, null) => 0,
|
||||
(_, null) => 1,
|
||||
(null, _) => -1,
|
||||
(final int ts1, final int ts2) => ts1.compareTo(ts2),
|
||||
};
|
||||
});
|
||||
|
||||
return timelineEvents;
|
||||
|
@ -546,12 +546,11 @@ 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}) {
|
||||
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}');
|
||||
return switch (key) {
|
||||
Uri() => MatchesGoldenFile(key, version),
|
||||
String() => MatchesGoldenFile.forStringPath(key, version),
|
||||
_ => throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}'),
|
||||
};
|
||||
}
|
||||
|
||||
/// Asserts that a [Finder], [Future<ui.Image>], or [ui.Image] matches a
|
||||
|
@ -932,14 +932,11 @@ class WidgetTester extends WidgetController implements HitTestDispatcher, Ticker
|
||||
|
||||
final Key? key = widget.key;
|
||||
if (key is ValueKey<dynamic>) {
|
||||
String? keyLabel;
|
||||
if (key is ValueKey<int> ||
|
||||
key is ValueKey<double> ||
|
||||
key is ValueKey<bool>) {
|
||||
keyLabel = 'const ${key.runtimeType}(${key.value})';
|
||||
} else if (key is ValueKey<String>) {
|
||||
keyLabel = "const Key('${key.value}')";
|
||||
}
|
||||
final String? keyLabel = switch (key.value) {
|
||||
int() || double() || bool() => 'const ${key.runtimeType}(${key.value})',
|
||||
final String value => "const Key('$value')",
|
||||
_ => null,
|
||||
};
|
||||
if (keyLabel != null) {
|
||||
final Iterable<Element> matches = find.byKey(key).evaluate();
|
||||
if (matches.length == 1) {
|
||||
|
@ -131,12 +131,11 @@ abstract class DeferredComponentsValidator {
|
||||
if (line.startsWith('Only in android')) {
|
||||
continue;
|
||||
}
|
||||
TerminalColor color = TerminalColor.grey;
|
||||
if (line.startsWith('+')) {
|
||||
color = TerminalColor.green;
|
||||
} else if (line.startsWith('-')) {
|
||||
color = TerminalColor.red;
|
||||
}
|
||||
final TerminalColor color = switch (line[0]) {
|
||||
'+' => TerminalColor.green,
|
||||
'-' => TerminalColor.red,
|
||||
_ => TerminalColor.grey,
|
||||
};
|
||||
logger.printStatus(line, color: color);
|
||||
}
|
||||
logger.printStatus('');
|
||||
|
@ -115,18 +115,15 @@ 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;
|
||||
|
@ -666,11 +666,10 @@ abstract class _BuildIOSSubCommand extends BuildSubCommand {
|
||||
|
||||
final String logTarget = environmentType == EnvironmentType.simulator ? 'simulator' : 'device';
|
||||
final String typeName = globals.artifacts!.getEngineType(TargetPlatform.ios, buildInfo.mode);
|
||||
if (xcodeBuildAction == XcodeBuildAction.build) {
|
||||
globals.printStatus('Building $app for $logTarget ($typeName)...');
|
||||
} else {
|
||||
globals.printStatus('Archiving $app...');
|
||||
}
|
||||
globals.printStatus(switch (xcodeBuildAction) {
|
||||
XcodeBuildAction.build => 'Building $app for $logTarget ($typeName)...',
|
||||
XcodeBuildAction.archive => 'Archiving $app...',
|
||||
});
|
||||
final XcodeBuildResult result = await buildXcodeProject(
|
||||
app: app,
|
||||
buildInfo: buildInfo,
|
||||
|
@ -429,22 +429,17 @@ end
|
||||
Directory simulatorBuildOutput,
|
||||
) async {
|
||||
const String appFrameworkName = 'App.framework';
|
||||
|
||||
final Status status = globals.logger.startProgress(
|
||||
' ├─Building App.xcframework...',
|
||||
);
|
||||
final List<EnvironmentType> environmentTypes = <EnvironmentType>[
|
||||
EnvironmentType.physical,
|
||||
EnvironmentType.simulator,
|
||||
];
|
||||
final List<Directory> frameworks = <Directory>[];
|
||||
|
||||
try {
|
||||
for (final EnvironmentType sdkType in environmentTypes) {
|
||||
final Directory outputBuildDirectory =
|
||||
sdkType == EnvironmentType.physical
|
||||
? iPhoneBuildOutput
|
||||
: simulatorBuildOutput;
|
||||
for (final EnvironmentType sdkType in EnvironmentType.values) {
|
||||
final Directory outputBuildDirectory = switch (sdkType) {
|
||||
EnvironmentType.physical => iPhoneBuildOutput,
|
||||
EnvironmentType.simulator => simulatorBuildOutput,
|
||||
};
|
||||
frameworks.add(outputBuildDirectory.childDirectory(appFrameworkName));
|
||||
final Environment environment = Environment(
|
||||
projectDir: globals.fs.currentDirectory,
|
||||
|
@ -1429,16 +1429,12 @@ Map<String, Object?> _operationResultToMap(OperationResult result) {
|
||||
}
|
||||
|
||||
Object? _toJsonable(Object? obj) {
|
||||
if (obj is String || obj is int || obj is bool || obj is Map<Object?, Object?> || obj is List<Object?> || obj == null) {
|
||||
return obj;
|
||||
}
|
||||
if (obj is OperationResult) {
|
||||
return _operationResultToMap(obj);
|
||||
}
|
||||
if (obj is ToolExit) {
|
||||
return obj.message;
|
||||
}
|
||||
return '$obj';
|
||||
return switch (obj) {
|
||||
String() || int() || bool() || Map<Object?, Object?>() || List<Object?>() || null => obj,
|
||||
OperationResult() => _operationResultToMap(obj),
|
||||
ToolExit() => obj.message,
|
||||
_ => obj.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
class NotifyingLogger extends DelegatingLogger {
|
||||
|
@ -942,12 +942,11 @@ enum ImpellerStatus {
|
||||
|
||||
const ImpellerStatus._(this.asBool);
|
||||
|
||||
factory ImpellerStatus.fromBool(bool? b) {
|
||||
if (b == null) {
|
||||
return platformDefault;
|
||||
}
|
||||
return b ? enabled : disabled;
|
||||
}
|
||||
factory ImpellerStatus.fromBool(bool? b) => switch (b) {
|
||||
true => enabled,
|
||||
false => disabled,
|
||||
null => platformDefault,
|
||||
};
|
||||
|
||||
final bool? asBool;
|
||||
}
|
||||
|
@ -439,15 +439,11 @@ class IOSCoreDevice {
|
||||
String? get udid => hardwareProperties?.udid;
|
||||
|
||||
DeviceConnectionInterface? get connectionInterface {
|
||||
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;
|
||||
return switch (connectionProperties?.transportType?.toLowerCase()) {
|
||||
'localnetwork' => DeviceConnectionInterface.wireless,
|
||||
'wired' => DeviceConnectionInterface.attached,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
|
@ -96,16 +96,12 @@ 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) {
|
||||
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.brace(this.positionInMessage, String this.value)
|
||||
: type = switch (value) {
|
||||
'{' => ST.openBrace,
|
||||
'}' => ST.closeBrace,
|
||||
_ => 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;
|
||||
|
@ -914,12 +914,10 @@ abstract class ResidentHandlers {
|
||||
final Brightness? current = await flutterDevices.first!.vmService!.flutterBrightnessOverride(
|
||||
isolateId: views.first.uiIsolate!.id!,
|
||||
);
|
||||
Brightness next;
|
||||
if (current == Brightness.light) {
|
||||
next = Brightness.dark;
|
||||
} else {
|
||||
next = Brightness.light;
|
||||
}
|
||||
final Brightness next = switch (current) {
|
||||
Brightness.light => Brightness.dark,
|
||||
Brightness.dark || null => Brightness.light,
|
||||
};
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
final List<FlutterView> views = await device!.vmService!.getFlutterViews();
|
||||
for (final FlutterView view in views) {
|
||||
|
@ -772,15 +772,14 @@ abstract class FlutterCommand extends Command<void> {
|
||||
return null;
|
||||
}();
|
||||
|
||||
DeviceConnectionInterface? get deviceConnectionInterface {
|
||||
DeviceConnectionInterface? get deviceConnectionInterface {
|
||||
if ((argResults?.options.contains(FlutterOptions.kDeviceConnection) ?? false)
|
||||
&& (argResults?.wasParsed(FlutterOptions.kDeviceConnection) ?? false)) {
|
||||
final String? connectionType = stringArg(FlutterOptions.kDeviceConnection);
|
||||
if (connectionType == 'attached') {
|
||||
return DeviceConnectionInterface.attached;
|
||||
} else if (connectionType == 'wireless') {
|
||||
return DeviceConnectionInterface.wireless;
|
||||
}
|
||||
return switch (stringArg(FlutterOptions.kDeviceConnection)) {
|
||||
'attached' => DeviceConnectionInterface.attached,
|
||||
'wireless' => DeviceConnectionInterface.wireless,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -290,13 +290,11 @@ class FakeDeviceManager implements DeviceManager {
|
||||
Device? getSingleEphemeralDevice(List<Device> devices) => null;
|
||||
|
||||
List<Device> filteredDevices(DeviceDiscoveryFilter? filter) {
|
||||
if (filter?.deviceConnectionInterface == DeviceConnectionInterface.attached) {
|
||||
return attachedDevices;
|
||||
}
|
||||
if (filter?.deviceConnectionInterface == DeviceConnectionInterface.wireless) {
|
||||
return wirelessDevices;
|
||||
}
|
||||
return attachedDevices + wirelessDevices;
|
||||
return switch (filter?.deviceConnectionInterface) {
|
||||
DeviceConnectionInterface.attached => attachedDevices,
|
||||
DeviceConnectionInterface.wireless => wirelessDevices,
|
||||
null => attachedDevices + wirelessDevices,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user