mirror of
https://github.com/flutter/flutter
synced 2024-08-27 20:10:11 +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
|
||||
- use_full_hex_values_for_flutter_colors
|
||||
# - 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_late_for_private_fields_and_variables
|
||||
# - 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
|
||||
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));
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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),
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -864,7 +864,7 @@ class _RepeatingSimulation extends Simulation {
|
|||
|
||||
final double totalTimeInSeconds = timeInSeconds + _initialT;
|
||||
final double t = (totalTimeInSeconds / _periodInSeconds) % 1.0;
|
||||
final bool _isPlayingReverse = (totalTimeInSeconds ~/ _periodInSeconds) % 2 == 1;
|
||||
final bool _isPlayingReverse = (totalTimeInSeconds ~/ _periodInSeconds).isOdd;
|
||||
|
||||
if (reverse && _isPlayingReverse) {
|
||||
directionSetter(_AnimationDirection.reverse);
|
||||
|
|
|
@ -711,7 +711,7 @@ class _RenderMergeableMaterialListBody extends RenderListBody {
|
|||
while (child != null) {
|
||||
final ListBodyParentData childParentData = child.parentData! as ListBodyParentData;
|
||||
final Rect rect = (childParentData.offset + offset) & child.size;
|
||||
if (i % 2 == 0)
|
||||
if (i.isEven)
|
||||
_paintShadows(context.canvas, rect);
|
||||
child = childParentData.nextSibling;
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
|
|||
markNeedsLayout();
|
||||
}
|
||||
|
||||
bool get _isVertical => quarterTurns % 2 == 1;
|
||||
bool get _isVertical => quarterTurns.isOdd;
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
|
|
|
@ -55,7 +55,7 @@ void main() {
|
|||
final Iterable<int> integers = CachingIterable<int>(range(1, 5).iterator);
|
||||
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(evens.first, equals(2));
|
||||
|
|
|
@ -515,7 +515,7 @@ void main() {
|
|||
addSemanticIndexes: false,
|
||||
itemCount: 250,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index % 2 == 0) {
|
||||
if (index.isEven) {
|
||||
return _AlwaysKeepAlive(
|
||||
key: GlobalObjectKey<_AlwaysKeepAliveState>(index),
|
||||
);
|
||||
|
|
|
@ -509,7 +509,7 @@ void main() {
|
|||
itemBuilder: (_, int i) => Container(
|
||||
height: 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) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: index % 2 == 0
|
||||
color: index.isEven
|
||||
? const Color(0xFF0000FF)
|
||||
: const Color(0xFF00FF00),
|
||||
child: Text(kStates[index]),
|
||||
|
@ -499,7 +499,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: index % 2 == 0
|
||||
color: index.isEven
|
||||
? const Color(0xFF0000FF)
|
||||
: const Color(0xFF00FF00),
|
||||
child: Text(kStates[index]),
|
||||
|
@ -543,7 +543,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: index % 2 == 0
|
||||
color: index.isEven
|
||||
? const Color(0xFF0000FF)
|
||||
: const Color(0xFF00FF00),
|
||||
child: Text(kStates[index]),
|
||||
|
@ -576,7 +576,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: index % 2 == 0
|
||||
color: index.isEven
|
||||
? const Color(0xFF0000FF)
|
||||
: const Color(0xFF00FF00),
|
||||
child: Text(kStates[index]),
|
||||
|
@ -615,7 +615,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 200.0,
|
||||
color: index % 2 == 0
|
||||
color: index.isEven
|
||||
? const Color(0xFF0000FF)
|
||||
: const Color(0xFF00FF00),
|
||||
child: Text(index.toString()),
|
||||
|
|
|
@ -49,7 +49,7 @@ void main() {
|
|||
controller: controller,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
color: index % 2 == 0 ? Colors.red : Colors.green,
|
||||
color: index.isEven ? Colors.red : Colors.green,
|
||||
height: 200.0,
|
||||
child: Text('Hello $index'),
|
||||
);
|
||||
|
|
|
@ -99,7 +99,7 @@ Widget _buildTestWidget({
|
|||
controller: controller,
|
||||
children: List<Widget>.generate(10, (int i) {
|
||||
return Container(
|
||||
color: i % 2 == 0 ? Colors.red : Colors.blue,
|
||||
color: i.isEven ? Colors.red : Colors.blue,
|
||||
height: 250.0,
|
||||
child: Text('Item $i'),
|
||||
);
|
||||
|
|
|
@ -72,7 +72,7 @@ void main() {
|
|||
(BuildContext _, int index) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
color: index % 2 == 0 ? Colors.red : Colors.yellow,
|
||||
color: index.isEven ? Colors.red : Colors.yellow,
|
||||
child: Text('Tile $index'),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -889,10 +889,10 @@ void main() {
|
|||
(BuildContext context, int index) {
|
||||
return Container(
|
||||
child: Material(
|
||||
color: index % 2 == 0 ? Colors.yellow : Colors.red,
|
||||
color: index.isEven ? Colors.yellow : Colors.red,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
index % 2 == 0 ? firstTapped++ : secondTapped++;
|
||||
index.isEven ? firstTapped++ : secondTapped++;
|
||||
},
|
||||
child: Text('Index $index'),
|
||||
),
|
||||
|
|
|
@ -26,7 +26,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
||||
color: index.isEven ? Colors.blue : Colors.red,
|
||||
child: Text('Tile $index'),
|
||||
);
|
||||
},
|
||||
|
@ -70,7 +70,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
||||
color: index.isEven ? Colors.blue : Colors.red,
|
||||
child: Text('Tile $index'),
|
||||
);
|
||||
},
|
||||
|
@ -114,7 +114,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
||||
color: index.isEven ? Colors.blue : Colors.red,
|
||||
child: Text('Tile $index'),
|
||||
);
|
||||
},
|
||||
|
@ -156,7 +156,7 @@ void main() {
|
|||
itemBuilder: (BuildContext context, int index) {
|
||||
return Container(
|
||||
height: 100.0,
|
||||
color: index % 2 == 0 ? Colors.blue : Colors.red,
|
||||
color: index.isEven ? Colors.blue : Colors.red,
|
||||
child: Text('Tile $index'),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -36,7 +36,7 @@ void main() {
|
|||
|
||||
expect(events.length, 8);
|
||||
for (int i = 0; i < events.length; ++i) {
|
||||
final bool isEven = i % 2 == 0;
|
||||
final bool isEven = i.isEven;
|
||||
if (isEven) {
|
||||
expect(events[i].runtimeType, equals(RawKeyDownEvent));
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue