mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
use_is_even_rather_than_modulo (#68301)
This commit is contained in:
parent
3393566b56
commit
c0176c9ee5
@ -216,7 +216,7 @@ linter:
|
|||||||
# - unsafe_html # not yet tested
|
# - unsafe_html # not yet tested
|
||||||
- use_full_hex_values_for_flutter_colors
|
- use_full_hex_values_for_flutter_colors
|
||||||
# - use_function_type_syntax_for_parameters # not yet tested
|
# - use_function_type_syntax_for_parameters # not yet tested
|
||||||
# - use_is_even_rather_than_modulo # not yet tested
|
- use_is_even_rather_than_modulo
|
||||||
# - use_key_in_widget_constructors # not yet tested
|
# - use_key_in_widget_constructors # not yet tested
|
||||||
- use_late_for_private_fields_and_variables
|
- use_late_for_private_fields_and_variables
|
||||||
# - use_raw_strings # not yet tested
|
# - use_raw_strings # not yet tested
|
||||||
|
@ -111,7 +111,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
|
|||||||
key: const Key('complex-scroll'), // this key is used by the driver test
|
key: const Key('complex-scroll'), // this key is used by the driver test
|
||||||
controller: ScrollController(), // So that the scroll offset can be tracked
|
controller: ScrollController(), // So that the scroll offset can be tracked
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
if (index % 2 == 0)
|
if (index.isEven)
|
||||||
return FancyImageItem(index, key: PageStorageKey<int>(index));
|
return FancyImageItem(index, key: PageStorageKey<int>(index));
|
||||||
else
|
else
|
||||||
return FancyGalleryItem(index, key: PageStorageKey<int>(index));
|
return FancyGalleryItem(index, key: PageStorageKey<int>(index));
|
||||||
|
@ -70,7 +70,7 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
|
|||||||
// This implementation rebuild the widget tree for every
|
// This implementation rebuild the widget tree for every
|
||||||
// frame, and is intentionally designed of poor performance
|
// frame, and is intentionally designed of poor performance
|
||||||
// for benchmark purposes.
|
// for benchmark purposes.
|
||||||
return counter % 2 == 0
|
return counter.isEven
|
||||||
? Container(
|
? Container(
|
||||||
// This key forces rebuilding the element
|
// This key forces rebuilding the element
|
||||||
key: ValueKey<int>(widgetCounter + label),
|
key: ValueKey<int>(widgetCounter + label),
|
||||||
|
@ -132,7 +132,7 @@ class ListItem extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Image.asset(
|
Image.asset(
|
||||||
index % 2 == 0 ? 'food/butternut_squash_soup.png' : 'food/cherry_pie.png',
|
index.isEven ? 'food/butternut_squash_soup.png' : 'food/cherry_pie.png',
|
||||||
package: 'flutter_gallery_assets',
|
package: 'flutter_gallery_assets',
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
width: 110,
|
width: 110,
|
||||||
|
@ -69,7 +69,7 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
|
|||||||
final double offsetY = row * cellSize.height;
|
final double offsetY = row * cellSize.height;
|
||||||
// Retain every other layer, so we exercise the update path 50% of the
|
// Retain every other layer, so we exercise the update path 50% of the
|
||||||
// time and the retain path the other 50%.
|
// time and the retain path the other 50%.
|
||||||
final bool shouldRetain = oldLayer != null && (row + col) % 2 == 0;
|
final bool shouldRetain = oldLayer != null && (row + col).isEven;
|
||||||
if (shouldRetain) {
|
if (shouldRetain) {
|
||||||
sceneBuilder.addRetained(oldLayer);
|
sceneBuilder.addRetained(oldLayer);
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,7 +21,7 @@ void main() {
|
|||||||
data.add(
|
data.add(
|
||||||
InlineSpanSemanticsInformation(words[i], isPlaceholder: false),
|
InlineSpanSemanticsInformation(words[i], isPlaceholder: false),
|
||||||
);
|
);
|
||||||
} else if (i % 2 == 0) {
|
} else if (i.isEven) {
|
||||||
data.add(
|
data.add(
|
||||||
InlineSpanSemanticsInformation(words[i], isPlaceholder: true),
|
InlineSpanSemanticsInformation(words[i], isPlaceholder: true),
|
||||||
);
|
);
|
||||||
|
@ -46,7 +46,7 @@ Future<void> main() async {
|
|||||||
|
|
||||||
watch.start();
|
watch.start();
|
||||||
while (watch.elapsed < kBenchmarkTime) {
|
while (watch.elapsed < kBenchmarkTime) {
|
||||||
renderView.configuration = (iterations % 2 == 0) ? big : small;
|
renderView.configuration = iterations.isEven ? big : small;
|
||||||
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
|
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
|
||||||
iterations += 1;
|
iterations += 1;
|
||||||
}
|
}
|
||||||
|
@ -1376,7 +1376,7 @@ class ReportedDurationTest {
|
|||||||
class ListStatistics {
|
class ListStatistics {
|
||||||
factory ListStatistics(Iterable<int> data) {
|
factory ListStatistics(Iterable<int> data) {
|
||||||
assert(data.isNotEmpty);
|
assert(data.isNotEmpty);
|
||||||
assert(data.length % 2 == 1);
|
assert(data.length.isOdd);
|
||||||
final List<int> sortedData = data.toList()..sort();
|
final List<int> sortedData = data.toList()..sort();
|
||||||
return ListStatistics._(
|
return ListStatistics._(
|
||||||
sortedData.first,
|
sortedData.first,
|
||||||
|
@ -28,7 +28,7 @@ class AsymmetricView extends StatelessWidget {
|
|||||||
return List<Container>.generate(_listItemCount(products.length), (int index) {
|
return List<Container>.generate(_listItemCount(products.length), (int index) {
|
||||||
double width = .59 * MediaQuery.of(context).size.width;
|
double width = .59 * MediaQuery.of(context).size.width;
|
||||||
Widget column;
|
Widget column;
|
||||||
if (index % 2 == 0) {
|
if (index.isEven) {
|
||||||
/// Even cases
|
/// Even cases
|
||||||
final int bottom = _evenCasesIndex(index);
|
final int bottom = _evenCasesIndex(index);
|
||||||
column = TwoProductCardColumn(
|
column = TwoProductCardColumn(
|
||||||
|
@ -864,7 +864,7 @@ class _RepeatingSimulation extends Simulation {
|
|||||||
|
|
||||||
final double totalTimeInSeconds = timeInSeconds + _initialT;
|
final double totalTimeInSeconds = timeInSeconds + _initialT;
|
||||||
final double t = (totalTimeInSeconds / _periodInSeconds) % 1.0;
|
final double t = (totalTimeInSeconds / _periodInSeconds) % 1.0;
|
||||||
final bool _isPlayingReverse = (totalTimeInSeconds ~/ _periodInSeconds) % 2 == 1;
|
final bool _isPlayingReverse = (totalTimeInSeconds ~/ _periodInSeconds).isOdd;
|
||||||
|
|
||||||
if (reverse && _isPlayingReverse) {
|
if (reverse && _isPlayingReverse) {
|
||||||
directionSetter(_AnimationDirection.reverse);
|
directionSetter(_AnimationDirection.reverse);
|
||||||
|
@ -711,7 +711,7 @@ class _RenderMergeableMaterialListBody extends RenderListBody {
|
|||||||
while (child != null) {
|
while (child != null) {
|
||||||
final ListBodyParentData childParentData = child.parentData! as ListBodyParentData;
|
final ListBodyParentData childParentData = child.parentData! as ListBodyParentData;
|
||||||
final Rect rect = (childParentData.offset + offset) & child.size;
|
final Rect rect = (childParentData.offset + offset) & child.size;
|
||||||
if (i % 2 == 0)
|
if (i.isEven)
|
||||||
_paintShadows(context.canvas, rect);
|
_paintShadows(context.canvas, rect);
|
||||||
child = childParentData.nextSibling;
|
child = childParentData.nextSibling;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
|
|||||||
markNeedsLayout();
|
markNeedsLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool get _isVertical => quarterTurns % 2 == 1;
|
bool get _isVertical => quarterTurns.isOdd;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
double computeMinIntrinsicWidth(double height) {
|
double computeMinIntrinsicWidth(double height) {
|
||||||
|
@ -55,7 +55,7 @@ void main() {
|
|||||||
final Iterable<int> integers = CachingIterable<int>(range(1, 5).iterator);
|
final Iterable<int> integers = CachingIterable<int>(range(1, 5).iterator);
|
||||||
expect(yieldCount, equals(0));
|
expect(yieldCount, equals(0));
|
||||||
|
|
||||||
final Iterable<int> evens = integers.where((int i) => i % 2 == 0);
|
final Iterable<int> evens = integers.where((int i) => i.isEven);
|
||||||
expect(yieldCount, equals(0));
|
expect(yieldCount, equals(0));
|
||||||
|
|
||||||
expect(evens.first, equals(2));
|
expect(evens.first, equals(2));
|
||||||
|
@ -515,7 +515,7 @@ void main() {
|
|||||||
addSemanticIndexes: false,
|
addSemanticIndexes: false,
|
||||||
itemCount: 250,
|
itemCount: 250,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
if (index % 2 == 0) {
|
if (index.isEven) {
|
||||||
return _AlwaysKeepAlive(
|
return _AlwaysKeepAlive(
|
||||||
key: GlobalObjectKey<_AlwaysKeepAliveState>(index),
|
key: GlobalObjectKey<_AlwaysKeepAliveState>(index),
|
||||||
);
|
);
|
||||||
|
@ -509,7 +509,7 @@ void main() {
|
|||||||
itemBuilder: (_, int i) => Container(
|
itemBuilder: (_, int i) => Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
width: 200.0,
|
width: 200.0,
|
||||||
color: i % 2 == 0 ? Colors.black : Colors.red,
|
color: i.isEven ? Colors.black : Colors.red,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -393,7 +393,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
color: index % 2 == 0
|
color: index.isEven
|
||||||
? const Color(0xFF0000FF)
|
? const Color(0xFF0000FF)
|
||||||
: const Color(0xFF00FF00),
|
: const Color(0xFF00FF00),
|
||||||
child: Text(kStates[index]),
|
child: Text(kStates[index]),
|
||||||
@ -499,7 +499,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
color: index % 2 == 0
|
color: index.isEven
|
||||||
? const Color(0xFF0000FF)
|
? const Color(0xFF0000FF)
|
||||||
: const Color(0xFF00FF00),
|
: const Color(0xFF00FF00),
|
||||||
child: Text(kStates[index]),
|
child: Text(kStates[index]),
|
||||||
@ -543,7 +543,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
color: index % 2 == 0
|
color: index.isEven
|
||||||
? const Color(0xFF0000FF)
|
? const Color(0xFF0000FF)
|
||||||
: const Color(0xFF00FF00),
|
: const Color(0xFF00FF00),
|
||||||
child: Text(kStates[index]),
|
child: Text(kStates[index]),
|
||||||
@ -576,7 +576,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
color: index % 2 == 0
|
color: index.isEven
|
||||||
? const Color(0xFF0000FF)
|
? const Color(0xFF0000FF)
|
||||||
: const Color(0xFF00FF00),
|
: const Color(0xFF00FF00),
|
||||||
child: Text(kStates[index]),
|
child: Text(kStates[index]),
|
||||||
@ -615,7 +615,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
color: index % 2 == 0
|
color: index.isEven
|
||||||
? const Color(0xFF0000FF)
|
? const Color(0xFF0000FF)
|
||||||
: const Color(0xFF00FF00),
|
: const Color(0xFF00FF00),
|
||||||
child: Text(index.toString()),
|
child: Text(index.toString()),
|
||||||
|
@ -49,7 +49,7 @@ void main() {
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
color: index % 2 == 0 ? Colors.red : Colors.green,
|
color: index.isEven ? Colors.red : Colors.green,
|
||||||
height: 200.0,
|
height: 200.0,
|
||||||
child: Text('Hello $index'),
|
child: Text('Hello $index'),
|
||||||
);
|
);
|
||||||
|
@ -99,7 +99,7 @@ Widget _buildTestWidget({
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
children: List<Widget>.generate(10, (int i) {
|
children: List<Widget>.generate(10, (int i) {
|
||||||
return Container(
|
return Container(
|
||||||
color: i % 2 == 0 ? Colors.red : Colors.blue,
|
color: i.isEven ? Colors.red : Colors.blue,
|
||||||
height: 250.0,
|
height: 250.0,
|
||||||
child: Text('Item $i'),
|
child: Text('Item $i'),
|
||||||
);
|
);
|
||||||
|
@ -72,7 +72,7 @@ void main() {
|
|||||||
(BuildContext _, int index) {
|
(BuildContext _, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
color: index % 2 == 0 ? Colors.red : Colors.yellow,
|
color: index.isEven ? Colors.red : Colors.yellow,
|
||||||
child: Text('Tile $index'),
|
child: Text('Tile $index'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -889,10 +889,10 @@ void main() {
|
|||||||
(BuildContext context, int index) {
|
(BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
child: Material(
|
child: Material(
|
||||||
color: index % 2 == 0 ? Colors.yellow : Colors.red,
|
color: index.isEven ? Colors.yellow : Colors.red,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
index % 2 == 0 ? firstTapped++ : secondTapped++;
|
index.isEven ? firstTapped++ : secondTapped++;
|
||||||
},
|
},
|
||||||
child: Text('Index $index'),
|
child: Text('Index $index'),
|
||||||
),
|
),
|
||||||
|
@ -26,7 +26,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
color: index.isEven ? Colors.blue : Colors.red,
|
||||||
child: Text('Tile $index'),
|
child: Text('Tile $index'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -70,7 +70,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
color: index.isEven ? Colors.blue : Colors.red,
|
||||||
child: Text('Tile $index'),
|
child: Text('Tile $index'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -114,7 +114,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
color: index.isEven ? Colors.blue : Colors.red,
|
||||||
child: Text('Tile $index'),
|
child: Text('Tile $index'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -156,7 +156,7 @@ void main() {
|
|||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 100.0,
|
height: 100.0,
|
||||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
color: index.isEven ? Colors.blue : Colors.red,
|
||||||
child: Text('Tile $index'),
|
child: Text('Tile $index'),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ void main() {
|
|||||||
|
|
||||||
expect(events.length, 8);
|
expect(events.length, 8);
|
||||||
for (int i = 0; i < events.length; ++i) {
|
for (int i = 0; i < events.length; ++i) {
|
||||||
final bool isEven = i % 2 == 0;
|
final bool isEven = i.isEven;
|
||||||
if (isEven) {
|
if (isEven) {
|
||||||
expect(events[i].runtimeType, equals(RawKeyDownEvent));
|
expect(events[i].runtimeType, equals(RawKeyDownEvent));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user