Reland "if chains → switch expressions" (#148634)
I did a goof a while back:

Now that [the bug is fixed](e9d403541f), I think we're good to re-implement the if-chains cleanup!
Related:
- https://github.com/flutter/flutter/pull/147793
- https://github.com/flutter/flutter/pull/148556
- https://github.com/flutter/flutter/issues/148548
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -35,11 +35,11 @@ class _SettingsIconPainter extends CustomPainter {
|
||||
/// The icon is aligned to the bottom-start corner.
|
||||
void _computeCenterAndScaling(Size size) {
|
||||
_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);
|
||||
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);
|
||||
}
|
||||
|
||||
/// Transforms an offset in relative units into an offset in logical pixels.
|
||||
|
||||
Reference in New Issue
Block a user