use_is_even_rather_than_modulo (#68301)

This commit is contained in:
Alexandre Ardhuin
2020-10-16 20:20:00 +02:00
committed by GitHub
parent 3393566b56
commit c0176c9ee5
22 changed files with 30 additions and 30 deletions

View File

@@ -111,7 +111,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
key: const Key('complex-scroll'), // this key is used by the driver test
controller: ScrollController(), // So that the scroll offset can be tracked
itemBuilder: (BuildContext context, int index) {
if (index % 2 == 0)
if (index.isEven)
return FancyImageItem(index, key: PageStorageKey<int>(index));
else
return FancyGalleryItem(index, key: PageStorageKey<int>(index));

View File

@@ -70,7 +70,7 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
// This implementation rebuild the widget tree for every
// frame, and is intentionally designed of poor performance
// for benchmark purposes.
return counter % 2 == 0
return counter.isEven
? Container(
// This key forces rebuilding the element
key: ValueKey<int>(widgetCounter + label),

View File

@@ -132,7 +132,7 @@ class ListItem extends StatelessWidget {
),
),
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',
fit: BoxFit.cover,
width: 110,

View File

@@ -69,7 +69,7 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
final double offsetY = row * cellSize.height;
// Retain every other layer, so we exercise the update path 50% of the
// 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) {
sceneBuilder.addRetained(oldLayer);
} else {

View File

@@ -21,7 +21,7 @@ void main() {
data.add(
InlineSpanSemanticsInformation(words[i], isPlaceholder: false),
);
} else if (i % 2 == 0) {
} else if (i.isEven) {
data.add(
InlineSpanSemanticsInformation(words[i], isPlaceholder: true),
);

View File

@@ -46,7 +46,7 @@ Future<void> main() async {
watch.start();
while (watch.elapsed < kBenchmarkTime) {
renderView.configuration = (iterations % 2 == 0) ? big : small;
renderView.configuration = iterations.isEven ? big : small;
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
iterations += 1;
}

View File

@@ -1376,7 +1376,7 @@ class ReportedDurationTest {
class ListStatistics {
factory ListStatistics(Iterable<int> data) {
assert(data.isNotEmpty);
assert(data.length % 2 == 1);
assert(data.length.isOdd);
final List<int> sortedData = data.toList()..sort();
return ListStatistics._(
sortedData.first,

View File

@@ -28,7 +28,7 @@ class AsymmetricView extends StatelessWidget {
return List<Container>.generate(_listItemCount(products.length), (int index) {
double width = .59 * MediaQuery.of(context).size.width;
Widget column;
if (index % 2 == 0) {
if (index.isEven) {
/// Even cases
final int bottom = _evenCasesIndex(index);
column = TwoProductCardColumn(