Modernize framework lints (#179089)

WIP

Commits separated as follows:
- Update lints in analysis_options files
- Run `dart fix --apply`
- Clean up leftover analysis issues 
- Run `dart format .` in the right places.

Local analysis and testing passes. Checking CI now.

Part of https://github.com/flutter/flutter/issues/178827
- Adoption of flutter_lints in examples/api coming in a separate change
(cc @loic-sharma)

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
Kate Lovett 2025-11-25 19:10:39 -06:00 committed by GitHub
parent 0e4cb8e86d
commit 9d96df2364
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2494 changed files with 38510 additions and 42441 deletions

View File

@ -40,11 +40,11 @@ linter:
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_specify_types
# - always_specify_types # conflicts with omit_obvious_local_variable_types
# - always_use_package_imports # we do this commonly
- annotate_overrides
- annotate_redeclares
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
# - avoid_annotating_with_dynamic # conflicts with type_annotate_public_apis
- avoid_bool_literals_in_conditional_expressions
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/4998
@ -78,7 +78,7 @@ linter:
- avoid_slow_async_io
- avoid_type_to_string
- avoid_types_as_parameter_names
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
# - avoid_types_on_closure_parameters # not yet tested
- avoid_unnecessary_containers
- avoid_unused_constructor_parameters
- avoid_void_async
@ -144,9 +144,9 @@ linter:
- noop_primitive_operations
- null_check_on_nullable_type_parameter
- null_closures
# - omit_local_variable_types # opposite of always_specify_types
# - omit_obvious_local_variable_types # not yet tested
# - omit_obvious_property_types # not yet tested
# - omit_local_variable_types # superset of omit_obvious_local_variable_types
- omit_obvious_local_variable_types # not yet tested
# - omit_obvious_property_types # conflicts with type_annotate_public_apis
# - one_member_abstracts # too many false positives
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
- overridden_fields
@ -204,13 +204,13 @@ linter:
- sort_constructors_first
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
- sort_unnamed_constructors_first
# - specify_nonobvious_local_variable_types # not yet tested
# - specify_nonobvious_property_types # not yet tested
- specify_nonobvious_local_variable_types
- specify_nonobvious_property_types
- strict_top_level_inference
- test_types_in_equals
- throw_in_finally
- tighten_type_of_initializing_formals
# - type_annotate_public_apis # subset of always_specify_types
- type_annotate_public_apis
- type_init_formals
- type_literal_in_constant_pattern
# - unawaited_futures # too many false positives, especially with the way AnimationController works

View File

@ -20,13 +20,13 @@ class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData lightTheme = ThemeData(
final lightTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xff6750a4),
contrastLevel: MediaQuery.highContrastOf(context) ? 1.0 : 0.0,
),
);
final ThemeData darkTheme = ThemeData(
final darkTheme = ThemeData(
colorScheme: ColorScheme.fromSeed(
brightness: Brightness.dark,
seedColor: const Color(0xff6750a4),
@ -34,7 +34,7 @@ class App extends StatelessWidget {
),
);
final Map<String, WidgetBuilder> routes = Map<String, WidgetBuilder>.fromEntries(
final routes = Map<String, WidgetBuilder>.fromEntries(
useCases.map(
(UseCase useCase) => MapEntry<String, WidgetBuilder>(
useCase.route,

View File

@ -42,7 +42,7 @@ void main() {
final SemanticsFinder tappables = find.semantics.byAction(SemanticsAction.tap);
final int tappableCount = tappables.evaluate().length;
for (int i = 0; i < tappableCount; i++) {
for (var i = 0; i < tappableCount; i++) {
final FinderBase<SemanticsNode> tappable = tappables.at(i);
final SemanticsNode node = tappable.evaluate().first;

View File

@ -36,10 +36,9 @@ void main() {
await pumpsUseCase(tester, AutoCompleteUseCase());
await tester.pumpAndSettle();
const List<String> kOptions = <String>['apple', 'banana', 'lemon'];
const String label = 'Fruit';
final String message =
'Type below to autocomplete the following possible results: $kOptions.\n$label';
const kOptions = <String>['apple', 'banana', 'lemon'];
const label = 'Fruit';
final message = 'Type below to autocomplete the following possible results: $kOptions.\n$label';
final SemanticsNode node = tester.semantics.find(find.bySemanticsLabel(message));
expect(node.flagsCollection.isTextField, isTrue);

View File

@ -33,7 +33,7 @@ import 'test_utils.dart';
void main() {
testWidgets('Has light and dark theme', (WidgetTester tester) async {
await tester.pumpWidget(const App());
final MaterialApp app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
final app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
expect(app.theme!.brightness, equals(Brightness.light));
expect(app.darkTheme!.brightness, equals(Brightness.dark));
});
@ -43,7 +43,7 @@ void main() {
const MediaQuery(data: MediaQueryData(highContrast: true), child: App()),
);
final MaterialApp app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
final app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
final DynamicScheme highContrastScheme = SchemeTonalSpot(
sourceColorHct: Hct.fromInt(const Color(0xff6750a4).value),
@ -214,7 +214,7 @@ void main() {
});
testWidgets('Each A11y Assessments page has a unique page title.', (WidgetTester tester) async {
final List<MethodCall> log = <MethodCall>[];
final log = <MethodCall>[];
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (
MethodCall methodCall,

View File

@ -10,7 +10,7 @@ import 'test_utils.dart';
void main() {
testWidgets('snack bar can run', (WidgetTester tester) async {
await pumpsUseCase(tester, SnackBarUseCase());
const String snackBarText = 'Awesome Snackbar!';
const snackBarText = 'Awesome Snackbar!';
expect(find.text(snackBarText), findsNothing);
await tester.tap(find.text('Show Snackbar'));
expect(find.text(snackBarText), findsNothing);

View File

@ -59,7 +59,7 @@ void main() {
testWidgets('text field wrapper exists', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldUseCase());
const String textFieldLabel = 'Input field with suffix @gmail.com';
const textFieldLabel = 'Input field with suffix @gmail.com';
final Finder semanticsWidgets = find.bySemanticsLabel(RegExp(textFieldLabel));
expect(semanticsWidgets, findsExactly(2));

View File

@ -87,12 +87,12 @@ const List<int> _kFailPngBytes = <int>[
];
void main() {
final List<String> log = <String>[];
final MemoryFileSystem fs = MemoryFileSystem();
final log = <String>[];
final fs = MemoryFileSystem();
final Directory basedir = fs.directory('flutter/test/library/')..createSync(recursive: true);
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient()
final fakeSkiaClient = FakeSkiaGoldClient()
..expectationForTestValues['flutter.new_golden_test.1'] = '';
final FlutterLocalFileComparator comparator = FlutterLocalFileComparator(
final comparator = FlutterLocalFileComparator(
basedir.uri,
fakeSkiaClient,
fs: fs,
@ -112,7 +112,7 @@ void main() {
),
isTrue,
);
const String expectation =
const expectation =
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.1.png. '
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
'Validate image output found at flutter/test/library/';
@ -128,7 +128,7 @@ void main() {
),
isTrue,
);
const String expectation =
const expectation =
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.2.png. '
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
'Validate image output found at flutter/test/library/';

View File

@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
// See //flutter/dev/bots/test.dart
void main() {
final Completer<void> complete = Completer<void>();
final complete = Completer<void>();
testWidgets('test smoke test -- this test SHOULD FAIL', (WidgetTester tester) async {
tester.runAsync(() async {

View File

@ -514,7 +514,7 @@ class ItemGalleryBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<String> tabNames = <String>['A', 'B', 'C', 'D'];
final tabNames = <String>['A', 'B', 'C', 'D'];
return SizedBox(
height: 200.0,

View File

@ -29,7 +29,7 @@ Iterable<PointerEvent> dragInputEvents(
final Offset movePerEvent = totalMove / moveEventCount.toDouble();
yield PointerAddedEvent(timeStamp: epoch, position: startLocation);
yield PointerDownEvent(timeStamp: epoch, position: startLocation, pointer: 1);
for (int t = 0; t < moveEventCount + 1; t++) {
for (var t = 0; t < moveEventCount + 1; t++) {
final Offset position = startLocation + movePerEvent * t.toDouble();
yield PointerMoveEvent(
timeStamp: epoch + totalTime * t ~/ moveEventCount,
@ -93,11 +93,10 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
Future<void> main() async {
final WidgetsBinding widgetsBinding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
assert(widgetsBinding is IntegrationTestWidgetsFlutterBinding);
final IntegrationTestWidgetsFlutterBinding binding =
widgetsBinding as IntegrationTestWidgetsFlutterBinding;
final binding = widgetsBinding as IntegrationTestWidgetsFlutterBinding;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
binding.reportData ??= <String, dynamic>{};
final ResampleFlagVariant variant = ResampleFlagVariant(binding);
final variant = ResampleFlagVariant(binding);
testWidgets(
'Smoothness test',
(WidgetTester tester) async {
@ -106,9 +105,9 @@ Future<void> main() async {
final Finder scrollerFinder = find.byKey(const ValueKey<String>('complex-scroll'));
final ListView scroller = tester.widget<ListView>(scrollerFinder);
final ScrollController? controller = scroller.controller;
final List<int> frameTimestamp = <int>[];
final List<double> scrollOffset = <double>[];
final List<Duration> delays = <Duration>[];
final frameTimestamp = <int>[];
final scrollOffset = <double>[];
final delays = <Duration>[];
binding.addPersistentFrameCallback((Duration timeStamp) {
if (controller?.hasClients ?? false) {
// This if is necessary because by the end of the test the widget tree
@ -142,7 +141,7 @@ Future<void> main() async {
}
}
for (int n = 0; n < 5; n++) {
for (var n = 0; n < 5; n++) {
await scroll();
}
variant.result = scrollSummary(scrollOffset, delays, frameTimestamp);
@ -205,8 +204,8 @@ Map<String, dynamic> scrollSummary(
) {
double jankyCount = 0;
double absJerkAvg = 0;
int lostFrame = 0;
for (int i = 1; i < scrollOffset.length - 1; i += 1) {
var lostFrame = 0;
for (var i = 1; i < scrollOffset.length - 1; i += 1) {
if (frameTimestamp[i + 1] - frameTimestamp[i - 1] > 40E3 ||
(i >= delays.length || delays[i] > const Duration(milliseconds: 16))) {
// filter data points from slow frame building or input simulation artifact

View File

@ -34,19 +34,19 @@ void main() {
expect(list, isNotNull);
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}, retainPriorEvents: true);
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -36,19 +36,19 @@ void main() {
expect(list, isNotNull);
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}, retainPriorEvents: true);
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -62,7 +62,7 @@ void main() {
'Expected exactly two "SEMANTICS" events, got ${semanticsEvents?.length}:\n$semanticsEvents',
);
}
final Duration semanticsTreeCreation = Duration(
final semanticsTreeCreation = Duration(
microseconds:
semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!,
);

View File

@ -20,7 +20,7 @@ const int maxIterations = 4;
const Duration pauses = Duration(milliseconds: 500);
Future<void> main() async {
final Completer<void> ready = Completer<void>();
final ready = Completer<void>();
runApp(
GestureDetector(
onTap: () {
@ -47,14 +47,14 @@ Future<void> main() async {
final WidgetController controller = LiveWidgetController(WidgetsBinding.instance);
// Scroll down
for (int iteration = 0; iteration < maxIterations; iteration += 1) {
for (var iteration = 0; iteration < maxIterations; iteration += 1) {
debugPrint('Scroll down... $iteration/$maxIterations');
await controller.fling(find.byType(ListView), const Offset(0.0, -700.0), speed);
await Future<void>.delayed(pauses);
}
// Scroll up
for (int iteration = 0; iteration < maxIterations; iteration += 1) {
for (var iteration = 0; iteration < maxIterations; iteration += 1) {
debugPrint('Scroll up... $iteration/$maxIterations');
await controller.fling(find.byType(ListView), const Offset(0.0, 300.0), speed);
await Future<void>.delayed(pauses);

View File

@ -11,15 +11,15 @@ class _MultiplyPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
const int xDenominator = 2;
const int yDenominator = 10;
const xDenominator = 2;
const yDenominator = 10;
final double width = size.width / xDenominator;
final double height = size.height / yDenominator;
for (int y = 0; y < yDenominator; y++) {
for (int x = 0; x < xDenominator; x++) {
for (var y = 0; y < yDenominator; y++) {
for (var x = 0; x < xDenominator; x++) {
final Rect rect = Offset(x * width, y * height) & Size(width, height);
final Paint basePaint = Paint()
final basePaint = Paint()
..color = Color.fromARGB(
(((x + 1) * width) / size.width * 255.0).floor(),
(((y + 1) * height) / size.height * 255.0).floor(),
@ -28,7 +28,7 @@ class _MultiplyPainter extends CustomPainter {
);
canvas.drawRect(rect, basePaint);
final Paint multiplyPaint = Paint()
final multiplyPaint = Paint()
..color = _color
..blendMode = BlendMode.multiply;
canvas.drawRect(rect, multiplyPaint);

View File

@ -41,7 +41,7 @@ class _ChunkedWork {
Future<void> start() async {
// Run 100 pieces of synchronous work.
// Chunked up to allow frames to be drawn.
for (int i = 0; i < 100; ++i) {
for (var i = 0; i < 100; ++i) {
_chunkedSynchronousWork();
}
}
@ -61,7 +61,7 @@ class _ChunkedWork {
}
void _syncComputationFor(Duration duration) {
final Stopwatch sw = Stopwatch()..start();
final sw = Stopwatch()..start();
while (!_canceled && sw.elapsed < duration) {}
}
}

View File

@ -72,7 +72,7 @@ class _ClipperCachePageState extends State<ClipperCachePage> with TickerProvider
}
Widget _makeChild(int itemIndex, bool complex) {
final BoxDecoration decoration = BoxDecoration(
final decoration = BoxDecoration(
color: Colors.white70,
boxShadow: const <BoxShadow>[BoxShadow(blurRadius: 5.0)],
borderRadius: BorderRadius.circular(5.0),

View File

@ -155,7 +155,7 @@ class _ShadowPainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
final Rect rect = Offset.zero & size;
final Paint paint = Paint();
final paint = Paint();
if (useColorFilter) {
paint.colorFilter = ColorFilter.mode(shadow.color, BlendMode.srcIn);
}

View File

@ -30,9 +30,9 @@ class Bezier extends StatelessWidget {
final double delay;
List<PathDetail> _getLogoPath() {
final List<PathDetail> paths = <PathDetail>[];
final paths = <PathDetail>[];
final Path path = Path();
final path = Path();
path.moveTo(100.0, 97.0);
path.cubicTo(100.0, 97.0, 142.0, 59.0, 169.91, 41.22);
path.cubicTo(197.82, 23.44, 249.24, 5.52, 204.67, 85.84);
@ -40,7 +40,7 @@ class Bezier extends StatelessWidget {
paths.add(PathDetail(path));
// Path 2
final Path bezier2Path = Path();
final bezier2Path = Path();
bezier2Path.moveTo(0.0, 70.55);
bezier2Path.cubicTo(0.0, 70.55, 42.0, 31.55, 69.91, 14.77);
bezier2Path.cubicTo(97.82, -2.01, 149.24, -20.93, 104.37, 59.39);
@ -48,7 +48,7 @@ class Bezier extends StatelessWidget {
paths.add(PathDetail(bezier2Path, translate: <double>[29.45, 151.0], rotation: -1.5708));
// Path 3
final Path bezier3Path = Path();
final bezier3Path = Path();
bezier3Path.moveTo(0.0, 69.48);
bezier3Path.cubicTo(0.0, 69.48, 44.82, 27.92, 69.91, 13.7);
bezier3Path.cubicTo(95.0, -0.52, 149.24, -22.0, 104.37, 58.32);
@ -56,7 +56,7 @@ class Bezier extends StatelessWidget {
paths.add(PathDetail(bezier3Path, translate: <double>[53.0, 200.48], rotation: -3.14159));
// Path 4
final Path bezier4Path = Path();
final bezier4Path = Path();
bezier4Path.moveTo(0.0, 69.48);
bezier4Path.cubicTo(0.0, 69.48, 43.82, 27.92, 69.91, 13.7);
bezier4Path.cubicTo(96.0, -0.52, 149.24, -22.0, 104.37, 58.32);
@ -114,13 +114,13 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
bool isReversed = false;
List<PathDetail> _playForward() {
final List<PathDetail> paths = <PathDetail>[];
final paths = <PathDetail>[];
final double t = curve.value;
final double b = controller.upperBound;
double pX;
double pY;
final Path path = Path();
final path = Path();
if (t < b / 2) {
pX = _getCubicPoint(t * 2, 100.0, 100.0, 142.0, 169.91);
@ -141,7 +141,7 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
paths.add(PathDetail(path));
// Path 2
final Path bezier2Path = Path();
final bezier2Path = Path();
if (t <= b / 2) {
final double pX = _getCubicPoint(t * 2, 0.0, 0.0, 42.0, 69.91);
@ -162,7 +162,7 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
paths.add(PathDetail(bezier2Path, translate: <double>[29.45, 151.0], rotation: -1.5708));
// Path 3
final Path bezier3Path = Path();
final bezier3Path = Path();
if (t <= b / 2) {
pX = _getCubicPoint(t * 2, 0.0, 0.0, 44.82, 69.91);
pY = _getCubicPoint(t * 2, 69.48, 69.48, 27.92, 13.7);
@ -182,7 +182,7 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
paths.add(PathDetail(bezier3Path, translate: <double>[53.0, 200.48], rotation: -3.14159));
// Path 4
final Path bezier4Path = Path();
final bezier4Path = Path();
if (t < b / 2) {
final double pX = _getCubicPoint(t * 2, 0.0, 0.0, 43.82, 69.91);
@ -213,15 +213,15 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
}
final List<Point> points = pointList[0];
final Path path = Path();
final path = Path();
path.moveTo(100.0, 97.0);
for (final Point point in points) {
for (final point in points) {
path.lineTo(point.x, point.y);
}
final Path bezier2Path = Path();
final bezier2Path = Path();
bezier2Path.moveTo(0.0, 70.55);
@ -229,14 +229,14 @@ class AnimatedBezierState extends State<AnimatedBezier> with SingleTickerProvide
bezier2Path.lineTo(p.x, p.y);
}
final Path bezier3Path = Path();
final bezier3Path = Path();
bezier3Path.moveTo(0.0, 69.48);
for (final Point p in pointList[2]) {
bezier3Path.lineTo(p.x, p.y);
}
final Path bezier4Path = Path();
final bezier4Path = Path();
bezier4Path.moveTo(0.0, 69.48);
@ -344,14 +344,14 @@ class BezierPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint paint = Paint();
final paint = Paint();
paint.strokeWidth = 18.0;
paint.style = PaintingStyle.stroke;
paint.strokeCap = StrokeCap.round;
paint.color = color;
canvas.scale(0.5, 0.5);
for (int i = 0; i < path.length; i++) {
for (var i = 0; i < path.length; i++) {
if (path[i].translate != null) {
canvas.translate(path[i].translate![0], path[i].translate![1]);
}
@ -361,7 +361,7 @@ class BezierPainter extends CustomPainter {
}
if (blur > 0) {
final MaskFilter blur = MaskFilter.blur(BlurStyle.normal, this.blur);
final blur = MaskFilter.blur(BlurStyle.normal, this.blur);
paint.maskFilter = blur;
canvas.drawPath(path[i].path, paint);
}

View File

@ -72,9 +72,9 @@ class ArcsPainter extends CustomPainter {
return;
}
canvas.drawPaint(Paint()..color = Colors.white);
for (int row = 0; row < numRows; row++) {
for (int col = 0; col < numCols; col++) {
final Offset center = Offset((col / numCols) * size.width, (row / numRows) * size.height);
for (var row = 0; row < numRows; row++) {
for (var col = 0; col < numCols; col++) {
final center = Offset((col / numCols) * size.width, (row / numRows) * size.height);
// Radius increases with row.
final double radius = row.toDouble();
// Sweep angle repeatedly goes from -2pi to 2pi.

View File

@ -70,13 +70,13 @@ class PointsPainter extends CustomPainter {
return;
}
canvas.drawPaint(Paint()..color = Colors.white);
for (int i = 0; i < 8; i++) {
for (var i = 0; i < 8; i++) {
final double x = ((size.width / (i + 1)) + tick) % size.width;
for (int j = 0; j < data.length; j += 2) {
for (var j = 0; j < data.length; j += 2) {
data[j] = x;
data[j + 1] = (size.height / (j + 1)) + 200;
}
final Paint paint = Paint()
final paint = Paint()
..color = kColors[i]
..strokeWidth = 5
..strokeCap = StrokeCap.round

View File

@ -73,7 +73,7 @@ class VerticesPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
canvas.translate(0, tick);
final ui.Vertices vertices = ui.Vertices(
final vertices = ui.Vertices(
VertexMode.triangles,
const <Offset>[
Offset.zero,

View File

@ -42,7 +42,7 @@ class _FilteredChildAnimationPageState extends State<FilteredChildAnimationPage>
_complexChild = widget.initialComplexChild;
_useRepaintBoundary = widget.initialUseRepaintBoundary;
WidgetsBinding.instance.addPostFrameCallback((_) {
final RenderBox childBox = _childKey.currentContext!.findRenderObject()! as RenderBox;
final childBox = _childKey.currentContext!.findRenderObject()! as RenderBox;
_childCenter = childBox.paintBounds.center;
});
_controller = AnimationController(vsync: this, duration: const Duration(seconds: 2));
@ -67,7 +67,7 @@ class _FilteredChildAnimationPageState extends State<FilteredChildAnimationPage>
};
static Widget _makeChild(int rows, int cols, double fontSize, bool complex) {
final BoxDecoration decoration = BoxDecoration(
final decoration = BoxDecoration(
color: Colors.green,
boxShadow: complex ? <BoxShadow>[const BoxShadow(blurRadius: 10.0)] : null,
borderRadius: BorderRadius.circular(10.0),

View File

@ -133,9 +133,9 @@ Color color(double factor) {
if (v < 0) {
v += 255 * 3;
}
int r = 0;
int g = 0;
int b = 0;
var r = 0;
var g = 0;
var b = 0;
if (v < 255) {
r = 255 - v;
g = v;
@ -156,10 +156,10 @@ Color color(double factor) {
Shader rotatingGradient(double factor, double x, double y, double h) {
final double s = sin(factor * 2 * pi) * h / 8;
final double c = cos(factor * 2 * pi) * h / 8;
final double cx = x;
final cx = x;
final double cy = y + h / 2;
final Offset p0 = Offset(cx + s, cy + c);
final Offset p1 = Offset(cx - s, cy - c);
final p0 = Offset(cx + s, cy + c);
final p1 = Offset(cx - s, cy - c);
return ui.Gradient.linear(p0, p1, <Color>[color(factor), color(factor + 0.5)]);
}
@ -193,11 +193,11 @@ class RecreatedDynamicGradients extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint p = Paint();
final p = Paint();
p.color = color(baseFactor);
canvas.drawRect(Offset.zero & size, p);
for (int j = 0; j < nDown; j++) {
for (int i = 0; i < nAcross; i++) {
for (var j = 0; j < nDown; j++) {
for (var i = 0; i < nAcross; i++) {
p.shader = gradient(baseFactor, i, j);
canvas.drawRect(Rect.fromLTWH(x(i, j), y(i, j), cellW, cellH), p);
}
@ -215,11 +215,11 @@ class RecreatedConsistentGradients extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint p = Paint();
final p = Paint();
p.color = color(baseFactor);
canvas.drawRect(Offset.zero & size, p);
for (int j = 0; j < nDown; j++) {
for (int i = 0; i < nAcross; i++) {
for (var j = 0; j < nDown; j++) {
for (var i = 0; i < nAcross; i++) {
p.shader = gradient(0, i, j);
canvas.drawRect(Rect.fromLTWH(x(i, j), y(i, j), cellW, cellH), p);
}
@ -241,11 +241,11 @@ class StaticConsistentGradients extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Paint p = Paint();
final p = Paint();
p.color = color(baseFactor);
canvas.drawRect(Offset.zero & size, p);
for (int j = 0; j < nDown; j++) {
for (int i = 0; i < nAcross; i++) {
for (var j = 0; j < nDown; j++) {
for (var i = 0; i < nAcross; i++) {
p.shader = gradients[j][i];
canvas.drawRect(Rect.fromLTWH(x(i, j), y(i, j), cellW, cellH), p);
}

View File

@ -173,8 +173,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
route: kOpacityPeepholeGridOfOpacityRouteName,
name: 'Grid of Opacity',
builder: (double v) {
double rowV = v;
double colV = rowV;
var rowV = v;
var colV = rowV;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@ -206,8 +206,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
route: kOpacityPeepholeOpacityOfGridRouteName,
name: 'Opacity of Grid',
builder: (double v) {
double rowV = v;
double colV = rowV;
var rowV = v;
var colV = rowV;
return Opacity(
opacity: _opacity(v),
child: SizedBox(
@ -238,8 +238,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
route: kOpacityPeepholeOpacityOfColOfRowsRouteName,
name: 'Opacity of Column of Rows',
builder: (double v) {
double rowV = v;
double colV = v;
var rowV = v;
var colV = v;
return Opacity(
opacity: _opacity(v),
child: Column(
@ -297,8 +297,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
child: SizedBox.expand(
child: CustomPaint(
painter: RectGridPainter((Canvas canvas, Size size) {
const int numRows = 10;
const int numCols = 7;
const numRows = 10;
const numCols = 7;
const double rectWidth = 30;
const double rectHeight = 30;
final double hGap = (size.width - numCols * rectWidth) / (numCols + 1);
@ -306,14 +306,14 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
final double gap = min(hGap, vGap);
final double xOffset = (size.width - (numCols * (rectWidth + gap) - gap)) * 0.5;
final double yOffset = (size.height - (numRows * (rectHeight + gap) - gap)) * 0.5;
final Paint rectPaint = Paint();
for (int r = 0; r < numRows; r++, v = 1 - v) {
final rectPaint = Paint();
for (var r = 0; r < numRows; r++, v = 1 - v) {
final double y = yOffset + r * (rectHeight + gap);
double cv = v;
for (int c = 0; c < numCols; c++, cv = 1 - cv) {
var cv = v;
for (var c = 0; c < numCols; c++, cv = 1 - cv) {
final double x = xOffset + c * (rectWidth + gap);
rectPaint.color = Color.fromRGBO(_red(cv), _green(cv), _blue(cv), _opacity(cv));
final Rect rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
final rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
canvas.drawRect(rect, rectPaint);
}
}
@ -332,8 +332,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
child: SizedBox.expand(
child: CustomPaint(
painter: RectGridPainter((Canvas canvas, Size size) {
const int numRows = 10;
const int numCols = 7;
const numRows = 10;
const numCols = 7;
const double rectWidth = 30;
const double rectHeight = 30;
final double hGap = (size.width - numCols * rectWidth) / (numCols + 1);
@ -341,16 +341,16 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
final double gap = min(hGap, vGap);
final double xOffset = (size.width - (numCols * (rectWidth + gap) - gap)) * 0.5;
final double yOffset = (size.height - (numRows * (rectHeight + gap) - gap)) * 0.5;
final Paint rectPaint = Paint();
final Paint layerPaint = Paint();
for (int r = 0; r < numRows; r++, v = 1 - v) {
final rectPaint = Paint();
final layerPaint = Paint();
for (var r = 0; r < numRows; r++, v = 1 - v) {
final double y = yOffset + r * (rectHeight + gap);
double cv = v;
for (int c = 0; c < numCols; c++, cv = 1 - cv) {
var cv = v;
for (var c = 0; c < numCols; c++, cv = 1 - cv) {
final double x = xOffset + c * (rectWidth + gap);
rectPaint.color = Color.fromRGBO(_red(cv), _green(cv), _blue(cv), 1.0);
layerPaint.color = Color.fromRGBO(255, 255, 255, _opacity(cv));
final Rect rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
final rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
canvas.saveLayer(null, layerPaint);
canvas.drawRect(rect, rectPaint);
canvas.restore();
@ -371,8 +371,8 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
child: SizedBox.expand(
child: CustomPaint(
painter: RectGridPainter((Canvas canvas, Size size) {
const int numRows = 10;
const int numCols = 7;
const numRows = 10;
const numCols = 7;
const double rectWidth = 30;
const double rectHeight = 30;
final double hGap = (size.width - numCols * rectWidth) / (numCols + 1);
@ -380,17 +380,17 @@ List<OpacityPeepholeCase> allOpacityPeepholeCases = <OpacityPeepholeCase>[
final double gap = min(hGap, vGap);
final double xOffset = (size.width - (numCols * (rectWidth + gap) - gap)) * 0.5;
final double yOffset = (size.height - (numRows * (rectHeight + gap) - gap)) * 0.5;
final Paint rectPaint = Paint();
final Paint layerPaint = Paint();
for (int r = 0; r < numRows; r++, v = 1 - v) {
final rectPaint = Paint();
final layerPaint = Paint();
for (var r = 0; r < numRows; r++, v = 1 - v) {
final double y = yOffset + r * (rectHeight + gap);
layerPaint.color = Color.fromRGBO(255, 255, 255, _opacity(v));
canvas.saveLayer(null, layerPaint);
double cv = v;
for (int c = 0; c < numCols; c++, cv = 1 - cv) {
var cv = v;
for (var c = 0; c < numCols; c++, cv = 1 - cv) {
final double x = xOffset + c * (rectWidth + gap);
rectPaint.color = Color.fromRGBO(_red(cv), _green(cv), _blue(cv), 1.0);
final Rect rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
final rect = Rect.fromLTWH(x, y, rectWidth, rectHeight);
canvas.drawRect(rect, rectPaint);
}
canvas.restore();

View File

@ -134,10 +134,10 @@ class IconRow extends StatelessWidget {
/// Parses SVG path data into a [Path] object.
Path _pathFromString(String pathString) {
int start = 0;
final RegExp pattern = RegExp('[MLCHVZ]');
var start = 0;
final pattern = RegExp('[MLCHVZ]');
Offset current = Offset.zero;
final Path path = Path();
final path = Path();
void performCommand(String command) {
final String type = command[0];
@ -196,7 +196,7 @@ class _SettingsIconPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Matrix4 scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
final scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
Path path;
path = _path1.transform(scale.storage)..fillType = PathFillType.evenOdd;
@ -256,7 +256,7 @@ class _CameraIconPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Matrix4 scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
final scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
Path path;
path = _path1.transform(scale.storage)..fillType = PathFillType.evenOdd;
@ -302,7 +302,7 @@ class _CalendarIconPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Matrix4 scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
final scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
Path path;
path = _path1.transform(scale.storage)..fillType = PathFillType.evenOdd;
@ -348,7 +348,7 @@ class _ConversationIconPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Matrix4 scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
final scale = Matrix4.diagonal3Values(size.width / 20, size.height / 20, 1.0);
Path path;
path = _path1.transform(scale.storage)..fillType = PathFillType.evenOdd;
@ -394,10 +394,10 @@ class _GeometryIconPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size canvasSize) {
const Size size = Size(20, 20);
const size = Size(20, 20);
canvas.scale(canvasSize.width / size.width, canvasSize.height / size.height);
final Paint paint = Paint()
final paint = Paint()
..color = const Color(0xFFF84F39)
..style = paintStyle
..strokeJoin = StrokeJoin.round

View File

@ -53,7 +53,7 @@ class ListItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> contents = <Widget>[
final contents = <Widget>[
const SizedBox(height: 15),
_buildUserInfo(),
const SizedBox(height: 10),

View File

@ -70,11 +70,11 @@ class PointsPainter extends CustomPainter {
return;
}
final double halfHeight = size.height / 2.0;
const double freq = 0.25;
const int circleCount = 40;
for (int i = 0; i < circleCount; ++i) {
const freq = 0.25;
const circleCount = 40;
for (var i = 0; i < circleCount; ++i) {
final double radius = 25 * cos(i + (1.0 * 2.0 * 3.1415 * tick) / 60.0) + 25;
final Paint paint = Paint()
final paint = Paint()
..style = PaintingStyle.fill
..filterQuality = FilterQuality.low
..maskFilter = MaskFilter.blur(BlurStyle.normal, radius);

View File

@ -71,11 +71,11 @@ class PointsPainter extends CustomPainter {
return;
}
final double halfHeight = size.height / 2.0;
const double freq = 0.25;
const int circleCount = 40;
for (int i = 0; i < circleCount; ++i) {
const freq = 0.25;
const circleCount = 40;
for (var i = 0; i < circleCount; ++i) {
final double radius = 25 * cos(i + (1.0 * 2.0 * 3.1415 * tick) / 60.0) + 25;
final Paint paint = Paint()
final paint = Paint()
..style = PaintingStyle.fill
..filterQuality = FilterQuality.low
..maskFilter = MaskFilter.blur(BlurStyle.normal, radius);

View File

@ -99,38 +99,38 @@ class PaintTest extends CustomPainter {
void paint(Canvas canvas, Size size) {
final double halfHeight = size.height / 2;
double x = 0;
const double strokeSize = .5;
const double zoomFactor = .5;
const strokeSize = .5;
const zoomFactor = .5;
final Paint paintPos = Paint()
final paintPos = Paint()
..color = Colors.pink
..strokeWidth = strokeSize
..isAntiAlias = false
..style = PaintingStyle.stroke;
final Paint paintNeg = Paint()
final paintNeg = Paint()
..color = Colors.pink
..strokeWidth = strokeSize
..isAntiAlias = false
..style = PaintingStyle.stroke;
final Paint paintZero = Paint()
final paintZero = Paint()
..color = Colors.green
..strokeWidth = strokeSize
..isAntiAlias = false
..style = PaintingStyle.stroke;
int index = 0;
var index = 0;
Paint? listPaint;
final Float32List offsets = Float32List(consolidate ? waveData.length * 4 : 4);
int used = 0;
final offsets = Float32List(consolidate ? waveData.length * 4 : 4);
var used = 0;
for (index = 0; index < waveData.length; index++) {
final (Paint curPaint, Offset p1) = switch (waveData[index]) {
< 0 => (paintPos, Offset(x, halfHeight * (1 - waveData[index] / 32768))),
> 0 => (paintNeg, Offset(x, halfHeight * (1 - waveData[index] / 32767))),
_ => (paintZero, Offset(x, halfHeight + 1)),
};
final Offset p0 = Offset(x, halfHeight);
final p0 = Offset(x, halfHeight);
if (consolidate) {
if (listPaint != null && listPaint != curPaint) {
canvas.drawRawPoints(PointMode.lines, offsets.sublist(0, used), listPaint);
@ -172,22 +172,22 @@ class PaintSomeTest extends CustomPainter {
void paint(Canvas canvas, Size size) {
final double halfHeight = size.height / 2;
double x = 0;
const double strokeSize = .5;
const double zoomFactor = .5;
const strokeSize = .5;
const zoomFactor = .5;
final Paint paintPos = Paint()
final paintPos = Paint()
..color = Colors.pink
..strokeWidth = strokeSize
..isAntiAlias = false
..style = PaintingStyle.stroke;
final Paint paintNeg = Paint()
final paintNeg = Paint()
..color = Colors.pink
..strokeWidth = strokeSize
..isAntiAlias = false
..style = PaintingStyle.stroke;
final Paint paintZero = Paint()
final paintZero = Paint()
..color = Colors.green
..strokeWidth = strokeSize
..isAntiAlias = false
@ -199,7 +199,7 @@ class PaintSomeTest extends CustomPainter {
> 0 => (paintNeg, Offset(x, halfHeight * (1 - waveData[index] / 32767))),
_ => (paintZero, Offset(x, halfHeight + 1)),
};
final Offset p0 = Offset(x, halfHeight);
final p0 = Offset(x, halfHeight);
canvas.drawLine(p0, p1, curPaint);
x += zoomFactor;
}
@ -215,9 +215,9 @@ class PaintSomeTest extends CustomPainter {
}
Int16List loadGraph() {
final Int16List waveData = Int16List(350000);
final Random r = Random(0x42);
for (int i = 0; i < waveData.length; i++) {
final waveData = Int16List(350000);
final r = Random(0x42);
for (var i = 0; i < waveData.length; i++) {
waveData[i] = r.nextInt(32768) - 16384;
}
return waveData;

View File

@ -42,10 +42,10 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
cellSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
rectSize = cellSize * 0.8;
final Paint paint = Paint()..color = const Color.fromARGB(255, 255, 0, 0);
for (int i = 0; i < kRows * kColumns; i++) {
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final paint = Paint()..color = const Color.fromARGB(255, 255, 0, 0);
for (var i = 0; i < kRows * kColumns; i++) {
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
canvas.drawRect(Offset.zero & rectSize, paint);
_pictures.add(pictureRecorder.endRecording());
}
@ -57,8 +57,8 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
@override
void onDrawFrame(SceneBuilder sceneBuilder) {
_rootLayer = sceneBuilder.pushOffset(0, 0, oldLayer: _rootLayer);
for (int row = 0; row < kRows; row++) {
for (int col = 0; col < kColumns; col++) {
for (var row = 0; row < kRows; row++) {
for (var col = 0; col < kColumns; col++) {
final int layerId = 1000000 * row + col;
final OffsetEngineLayer? oldLayer = _layers[layerId];
final double wobbleOffsetX = col * cellSize.width + (wobbleCounter - 5).abs();

View File

@ -42,14 +42,14 @@ class BenchClippedOutPictures extends SceneBuilderRecorder {
@override
void onDrawFrame(SceneBuilder sceneBuilder) {
final Size viewSize = view.physicalSize / view.devicePixelRatio;
final Size pictureSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
final pictureSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
// Fills a single cell with random text.
void fillCell(int row, int column) {
sceneBuilder.pushOffset(column * pictureSize.width, row * pictureSize.height);
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
canvas.save();
canvas.drawCircle(Offset(pictureSize.width / 2, pictureSize.height / 2), 5.0, paint);
canvas.drawRect(
@ -75,8 +75,8 @@ class BenchClippedOutPictures extends SceneBuilderRecorder {
);
sceneBuilder.pushOffset(5.0 * math.cos(angle), 5.0 * math.sin(angle));
angle += math.pi / 20;
for (int row = 0; row < 10; row++) {
for (int column = 0; column < 10; column++) {
for (var row = 0; row < 10; row++) {
for (var column = 0; column < 10; column++) {
fillCell(row, column);
}
}

View File

@ -22,7 +22,7 @@ class BenchDefaultTargetPlatform extends RawRecorder {
@override
void body(Profile profile) {
profile.record('runtime', () {
for (int i = 0; i < 10000; i++) {
for (var i = 0; i < 10000; i++) {
counter += defaultTargetPlatform.index;
}
}, reported: true);

View File

@ -47,7 +47,7 @@ class BenchDrawRect extends SceneBuilderRecorder {
Paint makePaint(int row, int col) {
if (benchmarkPaint) {
final Paint paint = Paint();
final paint = Paint();
final double rowRatio = row / kRows;
paint.color = Color.fromARGB(
255,
@ -70,16 +70,16 @@ class BenchDrawRect extends SceneBuilderRecorder {
@override
void onDrawFrame(SceneBuilder sceneBuilder) {
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
final Size viewSize = view.physicalSize;
final Size cellSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
final cellSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
final Size rectSize = cellSize * 0.8;
for (int row = 0; row < kRows; row++) {
for (var row = 0; row < kRows; row++) {
canvas.save();
for (int col = 0; col < kColumns; col++) {
for (var col = 0; col < kColumns; col++) {
canvas.drawRect(Offset((wobbleCounter - 5).abs(), 0) & rectSize, makePaint(row, col));
canvas.translate(cellSize.width, 0);
}

View File

@ -51,17 +51,17 @@ class BenchDrawRRectRSuperellipse extends SceneBuilderRecorder {
@override
void onDrawFrame(SceneBuilder sceneBuilder) {
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
final Size viewSize = view.physicalSize;
final Size cellSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
final cellSize = Size(viewSize.width / kColumns, viewSize.height / kRows);
final Size rectSize = cellSize * 0.8;
final double maxRadius = rectSize.shortestSide / 2;
for (int row = 0; row < kRows; row++) {
for (var row = 0; row < kRows; row++) {
canvas.save();
for (int col = 0; col < kColumns; col++) {
for (var col = 0; col < kColumns; col++) {
final double radius = maxRadius / kColumns * col;
_draw(
canvas,

View File

@ -48,9 +48,9 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder {
}
// Create one static picture, then never change it again.
const Color black = Color.fromARGB(255, 0, 0, 0);
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
const black = Color.fromARGB(255, 0, 0, 0);
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
viewSize = view.physicalSize / view.devicePixelRatio;
clipSize = Size(viewSize.width / 2, viewSize.height / 5);
final double cellWidth = viewSize.width / kColumns;
@ -63,10 +63,10 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder {
color: black,
);
int paragraphCounter = 0;
double yOffset = 0.0;
for (int row = 0; row < kRows; row += 1) {
for (int column = 0; column < kColumns; column += 1) {
var paragraphCounter = 0;
var yOffset = 0.0;
for (var row = 0; row < kRows; row += 1) {
for (var column = 0; column < kColumns; column += 1) {
final double left = cellWidth * column;
canvas.save();
canvas.clipRect(Rect.fromLTWH(left, yOffset, cellWidth, 20.0));
@ -96,7 +96,7 @@ class BenchDynamicClipOnStaticPicture extends SceneBuilderRecorder {
// This will move the clip along the Y axis in picture's local coordinates
// causing a repaint. If we're not efficient at managing clips and/or
// repaints this will jank (see https://github.com/flutter/flutter/issues/42987).
final Rect clip = Rect.fromLTWH(0.0, 0.0, clipSize.width, clipSize.height);
final clip = Rect.fromLTWH(0.0, 0.0, clipSize.width, clipSize.height);
sceneBuilder.pushClipRect(clip);
sceneBuilder.pushOffset(0.0, pictureVerticalOffset);
sceneBuilder.addPicture(Offset.zero, picture);

View File

@ -39,9 +39,9 @@ class BenchImageDecoding extends RawRecorder {
}
for (final String imageUrl in _imageUrls) {
final Future<JSAny?> fetchFuture = web.window.fetch(imageUrl.toJS).toDart;
final web.Response image = (await fetchFuture)! as web.Response;
final image = (await fetchFuture)! as web.Response;
final Future<JSAny?> imageFuture = image.arrayBuffer().toDart;
final JSArrayBuffer imageBuffer = (await imageFuture)! as JSArrayBuffer;
final imageBuffer = (await imageFuture)! as JSArrayBuffer;
_imageData.add(imageBuffer.toDart.asUint8List());
}
}
@ -58,7 +58,7 @@ class BenchImageDecoding extends RawRecorder {
@override
Future<void> body(Profile profile) async {
await profile.recordAsync('recordImageDecode', () async {
final List<Future<void>> allDecodes = <Future<void>>[
final allDecodes = <Future<void>>[
for (final Uint8List data in _imageData) _decodeImage(data),
];
await Future.wait(allDecodes);
@ -76,14 +76,14 @@ class BenchImageDecoding extends RawRecorder {
Future<void> _decodeImage(Uint8List data) async {
final ui.Codec codec = await ui.instantiateImageCodec(data);
const int decodeFrameCount = 5;
const decodeFrameCount = 5;
if (codec.frameCount < decodeFrameCount) {
throw Exception(
'Test image contains too few frames for this benchmark (${codec.frameCount}). '
'Choose a test image with at least $decodeFrameCount frames.',
);
}
for (int i = 0; i < decodeFrameCount; i++) {
for (var i = 0; i < decodeFrameCount; i++) {
(await codec.getNextFrame()).image.dispose();
}
codec.dispose();

View File

@ -125,7 +125,7 @@ class _ScrollTestState extends State<_ScrollTest> with SingleTickerProviderState
scrollController = ScrollController();
bool forward = true;
var forward = true;
// A one-off timer is necessary to allow the framework to measure the
// available scroll extents before the scroll controller can be exercised

View File

@ -22,7 +22,7 @@ class _NestedMouseRegion extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget current = child;
for (int i = 0; i < nests; i++) {
for (var i = 0; i < nests; i++) {
current = MouseRegion(onEnter: (_) {}, child: child);
}
return current;
@ -47,7 +47,7 @@ class BenchMouseRegionGridHover extends WidgetRecorder {
// Use a non-trivial border to force Web to switch painter
Border _getBorder(int columnIndex, int rowIndex) {
const BorderSide defaultBorderSide = BorderSide();
const defaultBorderSide = BorderSide();
return Border(
left: columnIndex == 0 ? defaultBorderSide : BorderSide.none,
@ -73,8 +73,8 @@ class BenchMouseRegionGridHover extends WidgetRecorder {
@override
Widget createWidget() {
const int rowsCount = 60;
const int columnsCount = 20;
const rowsCount = 60;
const columnsCount = 20;
const double containerSize = 20;
return Directionality(
textDirection: TextDirection.ltr,
@ -154,7 +154,7 @@ class _Tester {
Future<void> _hoverTo(Offset location, Duration duration) async {
currentTime += duration;
final Stopwatch stopwatch = Stopwatch()..start();
final stopwatch = Stopwatch()..start();
await gesture.moveTo(location, timeStamp: currentTime);
stopwatch.stop();
onDataPoint(stopwatch.elapsed);

View File

@ -25,7 +25,7 @@ class BenchMouseRegionGridScroll extends WidgetRecorder {
// Use a non-trivial border to force Web to switch painter
Border _getBorder(int columnIndex, int rowIndex) {
const BorderSide defaultBorderSide = BorderSide();
const defaultBorderSide = BorderSide();
return Border(
left: columnIndex == 0 ? defaultBorderSide : BorderSide.none,
@ -51,8 +51,8 @@ class BenchMouseRegionGridScroll extends WidgetRecorder {
@override
Widget createWidget() {
const int rowsCount = 60;
const int columnsCount = 20;
const rowsCount = 60;
const columnsCount = 20;
const double containerSize = 20;
return Directionality(
textDirection: TextDirection.ltr,
@ -138,7 +138,7 @@ class _Tester {
await gesture.down(start, timeStamp: currentTime);
for (int frame = 0; frame < fullFrames; frame += 1) {
for (var frame = 0; frame < fullFrames; frame += 1) {
currentTime += fullFrameDuration;
await gesture.moveBy(fullFrameOffset, timeStamp: currentTime);
await _UntilNextFrame.wait();

View File

@ -22,7 +22,7 @@ class _NestedMouseRegion extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget current = child;
for (int i = 0; i < nests; i++) {
for (var i = 0; i < nests; i++) {
current = MouseRegion(onEnter: (_) {}, child: child);
}
return current;
@ -38,7 +38,7 @@ class _NestedListener extends StatelessWidget {
@override
Widget build(BuildContext context) {
Widget current = child;
for (int i = 0; i < nests; i++) {
for (var i = 0; i < nests; i++) {
current = Listener(onPointerDown: (_) {}, child: child);
}
return current;
@ -63,7 +63,7 @@ class BenchMouseRegionMixedGridHover extends WidgetRecorder {
// Use a non-trivial border to force Web to switch painter
Border _getBorder(int columnIndex, int rowIndex) {
const BorderSide defaultBorderSide = BorderSide();
const defaultBorderSide = BorderSide();
return Border(
left: columnIndex == 0 ? defaultBorderSide : BorderSide.none,
@ -89,8 +89,8 @@ class BenchMouseRegionMixedGridHover extends WidgetRecorder {
@override
Widget createWidget() {
const int rowsCount = 60;
const int columnsCount = 20;
const rowsCount = 60;
const columnsCount = 20;
const double containerSize = 20;
return Directionality(
textDirection: TextDirection.ltr,
@ -175,7 +175,7 @@ class _Tester {
Future<void> _hoverTo(Offset location, Duration duration) async {
currentTime += duration;
final Stopwatch stopwatch = Stopwatch()..start();
final stopwatch = Stopwatch()..start();
await gesture.moveTo(location, timeStamp: currentTime);
stopwatch.stop();
onDataPoint(stopwatch.elapsed);

View File

@ -95,22 +95,18 @@ class _CustomPainter extends CustomPainter {
_textPainter.textDirection = TextDirection.ltr;
_textPainter.textWidthBasis = TextWidthBasis.longestLine;
_textPainter.textScaler = TextScaler.noScaling;
const TextStyle textStyle = TextStyle(
color: Colors.black87,
fontSize: 13,
fontFamily: 'Roboto',
);
const textStyle = TextStyle(color: Colors.black87, fontSize: 13, fontFamily: 'Roboto');
_linePainter.isAntiAlias = true;
for (int i = 0; i < 42; i++) {
for (var i = 0; i < 42; i++) {
_linePainter.color = Colors.white;
TextStyle temp = textStyle;
var temp = textStyle;
if (i % 7 == 0) {
temp = textStyle.copyWith(decoration: TextDecoration.lineThrough);
}
final TextSpan span = TextSpan(text: text, style: temp);
final span = TextSpan(text: text, style: temp);
_textPainter.text = span;
@ -147,7 +143,7 @@ class _CustomPainter extends CustomPainter {
_linePainter.strokeWidth = lineWidth;
_linePainter.color = Colors.grey;
canvas.drawLine(const Offset(0, lineWidth), Offset(size.width, lineWidth), _linePainter);
for (int i = 0; i < 6; i++) {
for (var i = 0; i < 6; i++) {
canvas.drawLine(Offset(0, yPosition), Offset(size.width, yPosition), _linePainter);
yPosition += height;
}
@ -159,7 +155,7 @@ class _CustomPainter extends CustomPainter {
);
xPosition = width;
canvas.drawLine(const Offset(lineWidth, 0), Offset(lineWidth, size.height), _linePainter);
for (int i = 0; i < 6; i++) {
for (var i = 0; i < 6; i++) {
canvas.drawLine(Offset(xPosition, 0), Offset(xPosition, size.height), _linePainter);
xPosition += width;
}

View File

@ -20,7 +20,7 @@ class BenchPathRecording extends RawRecorder {
@override
void body(Profile profile) {
profile.record('recordPathConstruction', () {
for (int i = 1; i <= 10; i++) {
for (var i = 1; i <= 10; i++) {
recording.createPaths();
}
}, reported: true);

View File

@ -43,14 +43,14 @@ class BenchPictureRecording extends RawRecorder {
@override
void body(Profile profile) {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
final recorder = PictureRecorder();
final canvas = Canvas(recorder);
profile.record('recordPaintCommands', () {
for (int i = 1; i <= 100; i++) {
for (var i = 1; i <= 100; i++) {
canvas.translate((10 + i).toDouble(), (10 + i).toDouble());
canvas.save();
for (int j = 0; j < 10; j++) {
for (var j = 0; j < 10; j++) {
canvas.drawRect(const Rect.fromLTWH(10, 10, 10, 10), paint);
canvas.drawCircle(const Offset(50, 50), 50, paint);
canvas.rotate(1.0);
@ -58,7 +58,7 @@ class BenchPictureRecording extends RawRecorder {
canvas.restore();
canvas.save();
for (int j = 0; j < 10; j++) {
for (var j = 0; j < 10; j++) {
canvas.translate(1, 1);
canvas.clipRect(Rect.fromLTWH(20, 20, 40 / i, 40));
canvas.drawRRect(

View File

@ -79,7 +79,7 @@ class _TestScrollingWidgetState extends State<_TestScrollingWidget> {
// Without the timer the animation doesn't begin.
Timer.run(() async {
bool forward = true;
var forward = true;
while (true) {
await scrollController.animateTo(
forward ? widget.initialScrollOffset + widget.scrollDistance : widget.initialScrollOffset,

View File

@ -29,7 +29,7 @@ class ParagraphGenerator {
/// Randomizes the given [text] and creates a paragraph with a unique
/// font-size so that the engine doesn't reuse a cached ruler.
ui.Paragraph generate(String text, {int? maxLines, bool hasEllipsis = false}) {
final ui.ParagraphBuilder builder =
final builder =
ui.ParagraphBuilder(
ui.ParagraphStyle(
fontFamily: 'sans-serif',
@ -108,15 +108,15 @@ class BenchTextLayout extends RawRecorder {
paragraph.layout(ui.ParagraphConstraints(width: maxWidth));
}, reported: true);
profile.record('$keyPrefix.getBoxesForRange', () {
for (int start = 0; start < text.length; start += 3) {
for (var start = 0; start < text.length; start += 3) {
for (int end = start + 1; end < text.length; end *= 2) {
paragraph.getBoxesForRange(start, end);
}
}
}, reported: true);
profile.record('$keyPrefix.getPositionForOffset', () {
for (double dx = 0.0; dx < paragraph.width; dx += 10.0) {
for (double dy = 0.0; dy < paragraph.height; dy += 10.0) {
for (var dx = 0.0; dx < paragraph.width; dx += 10.0) {
for (var dy = 0.0; dy < paragraph.height; dy += 10.0) {
paragraph.getPositionForOffset(Offset(dx, dy));
}
}
@ -136,13 +136,12 @@ class BenchTextCachedLayout extends RawRecorder {
@override
void body(Profile profile) {
final ui.ParagraphBuilder builder =
ui.ParagraphBuilder(ui.ParagraphStyle(fontFamily: 'sans-serif'))
..pushStyle(ui.TextStyle(fontSize: 12.0))
..addText(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
);
final builder = ui.ParagraphBuilder(ui.ParagraphStyle(fontFamily: 'sans-serif'))
..pushStyle(ui.TextStyle(fontSize: 12.0))
..addText(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
);
final ui.Paragraph paragraph = builder.build();
profile.record('layout', () {
paragraph.layout(const ui.ParagraphConstraints(width: double.infinity));

View File

@ -29,8 +29,8 @@ import 'test_data.dart';
/// performance issues: https://github.com/flutter/flutter/issues/48516
class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
BenchTextOutOfPictureBounds() : super(name: benchmarkName) {
const Color red = Color.fromARGB(255, 255, 0, 0);
const Color green = Color.fromARGB(255, 0, 255, 0);
const red = Color.fromARGB(255, 255, 0, 0);
const green = Color.fromARGB(255, 0, 255, 0);
// We don't want paragraph generation and layout to pollute benchmark numbers.
singleLineParagraphs = generateLaidOutParagraphs(
@ -59,10 +59,10 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
@override
void onDrawFrame(SceneBuilder sceneBuilder) {
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final pictureRecorder = PictureRecorder();
final canvas = Canvas(pictureRecorder);
final Size viewSize = view.physicalSize;
const double padding = 10.0;
const padding = 10.0;
// Fills a single cell with random text.
void fillCellWithText(List<Paragraph> textSource) {
@ -83,9 +83,9 @@ class BenchTextOutOfPictureBounds extends SceneBuilderRecorder {
// Starting with the top-left cell, fill every cell with text.
canvas.translate(-viewSize.width, -viewSize.height);
for (int row = 0; row < 3; row++) {
for (var row = 0; row < 3; row++) {
canvas.save();
for (int col = 0; col < 3; col++) {
for (var col = 0; col < 3; col++) {
canvas.drawRect(
Offset.zero & viewSize,
Paint()

View File

@ -1432,7 +1432,7 @@ class SnackBarSection extends StatelessWidget {
tooltipMessage: 'Use ScaffoldMessenger.of(context).showSnackBar with SnackBar',
child: TextButton(
onPressed: () {
final SnackBar snackBar = SnackBar(
final snackBar = SnackBar(
behavior: SnackBarBehavior.floating,
width: 400.0,
content: const Text('This is a snackbar'),
@ -1461,7 +1461,7 @@ class _BottomSheetSectionState extends State<BottomSheetSection> {
@override
Widget build(BuildContext context) {
List<Widget> buttonList = <Widget>[
var buttonList = <Widget>[
IconButton(onPressed: () {}, icon: const Icon(Icons.share_outlined)),
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
IconButton(onPressed: () {}, icon: const Icon(Icons.delete_outline)),
@ -1469,7 +1469,7 @@ class _BottomSheetSectionState extends State<BottomSheetSection> {
IconButton(onPressed: () {}, icon: const Icon(Icons.settings_outlined)),
IconButton(onPressed: () {}, icon: const Icon(Icons.favorite_border)),
];
const List<Text> labelList = <Text>[
const labelList = <Text>[
Text('Share'),
Text('Add to'),
Text('Trash'),
@ -1949,7 +1949,7 @@ class _MenusState extends State<Menus> {
@override
Widget build(BuildContext context) {
final List<DropdownMenuEntry<ColorLabel>> colorEntries = <DropdownMenuEntry<ColorLabel>>[];
final colorEntries = <DropdownMenuEntry<ColorLabel>>[];
for (final ColorLabel color in ColorLabel.values) {
colorEntries.add(
DropdownMenuEntry<ColorLabel>(
@ -1960,7 +1960,7 @@ class _MenusState extends State<Menus> {
);
}
final List<DropdownMenuEntry<IconLabel>> iconEntries = <DropdownMenuEntry<IconLabel>>[];
final iconEntries = <DropdownMenuEntry<IconLabel>>[];
for (final IconLabel icon in IconLabel.values) {
iconEntries.add(DropdownMenuEntry<IconLabel>(value: icon, label: icon.label));
}

View File

@ -50,7 +50,7 @@ const String kProfileApplyFrame = 'apply_frame';
///
/// * [timeAsyncAction], which measures the time of asynchronous work.
Duration timeAction(VoidCallback action) {
final Stopwatch stopwatch = Stopwatch()..start();
final stopwatch = Stopwatch()..start();
action();
stopwatch.stop();
return stopwatch.elapsed;
@ -62,7 +62,7 @@ Duration timeAction(VoidCallback action) {
///
/// * [timeAction], which measures the time of synchronous work.
Future<Duration> timeAsyncAction(AsyncCallback action) async {
final Stopwatch stopwatch = Stopwatch()..start();
final stopwatch = Stopwatch()..start();
await action();
stopwatch.stop();
return stopwatch.elapsed;
@ -259,7 +259,7 @@ abstract class SceneBuilderRecorder extends Recorder {
@override
Future<Profile> run() {
final Completer<Profile> profileCompleter = Completer<Profile>();
final profileCompleter = Completer<Profile>();
_profile = Profile(name: name);
PlatformDispatcher.instance.onBeginFrame = (_) {
@ -274,7 +274,7 @@ abstract class SceneBuilderRecorder extends Recorder {
PlatformDispatcher.instance.onDrawFrame = () {
try {
_profile!.record('drawFrameDuration', () {
final SceneBuilder sceneBuilder = SceneBuilder();
final sceneBuilder = SceneBuilder();
onDrawFrame(sceneBuilder);
_profile!.record('sceneBuildDuration', () {
final Scene scene = sceneBuilder.build();
@ -696,7 +696,7 @@ class Timeseries {
? _computeAverage(name, outliers)
: cleanAverage;
final List<AnnotatedSample> annotatedValues = <AnnotatedSample>[
final annotatedValues = <AnnotatedSample>[
for (final double warmUpValue in warmUpValues)
AnnotatedSample(
magnitude: warmUpValue,
@ -816,7 +816,7 @@ class TimeseriesStats {
@override
String toString() {
final StringBuffer buffer = StringBuffer();
final buffer = StringBuffer();
buffer.writeln(
'$name: (samples: $cleanSampleCount clean/$outlierSampleCount '
'outliers/${cleanSampleCount + outlierSampleCount} '
@ -1025,8 +1025,8 @@ class Profile {
/// Returns a JSON representation of the profile that will be sent to the
/// server.
Map<String, dynamic> toJson() {
final List<String> scoreKeys = <String>[];
final Map<String, dynamic> json = <String, dynamic>{'name': name, 'scoreKeys': scoreKeys};
final scoreKeys = <String>[];
final json = <String, dynamic>{'name': name, 'scoreKeys': scoreKeys};
for (final String key in scoreData.keys) {
final Timeseries timeseries = scoreData[key]!;
@ -1053,7 +1053,7 @@ class Profile {
@override
String toString() {
final StringBuffer buffer = StringBuffer();
final buffer = StringBuffer();
buffer.writeln('name: $name');
for (final String key in scoreData.keys) {
final Timeseries timeseries = scoreData[key]!;
@ -1064,7 +1064,7 @@ class Profile {
final dynamic value = extraData[key];
if (value is List) {
buffer.writeln('$key:');
for (final dynamic item in value) {
for (final Object? item in value) {
buffer.writeln(' - $item');
}
} else {

View File

@ -40,19 +40,19 @@ List<Paragraph> generateLaidOutParagraphs({
required double widthConstraint,
required Color color,
}) {
final List<Paragraph> strings = <Paragraph>[];
int wordPointer = 0; // points to the next word in lipsum to extract
for (int i = 0; i < paragraphCount; i++) {
final strings = <Paragraph>[];
var wordPointer = 0; // points to the next word in lipsum to extract
for (var i = 0; i < paragraphCount; i++) {
final int wordCount =
minWordCountPerParagraph +
_random.nextInt(maxWordCountPerParagraph - minWordCountPerParagraph + 1);
final List<String> string = <String>[];
for (int j = 0; j < wordCount; j++) {
final string = <String>[];
for (var j = 0; j < wordCount; j++) {
string.add(lipsum[wordPointer]);
wordPointer = (wordPointer + 1) % lipsum.length;
}
final ParagraphBuilder builder = ParagraphBuilder(ParagraphStyle(fontFamily: 'sans-serif'))
final builder = ParagraphBuilder(ParagraphStyle(fontFamily: 'sans-serif'))
..pushStyle(TextStyle(color: color, fontSize: 18.0))
..addText(string.join(' '))
..pop();

View File

@ -89,7 +89,7 @@ final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
late final LocalBenchmarkServerClient _client;
Future<void> main(List<String> args) async {
final ArgParser parser = ArgParser()
final parser = ArgParser()
..addOption(
'port',
abbr: 'p',
@ -139,7 +139,7 @@ Future<void> _runBenchmark(String benchmarkName) async {
await runZoned<Future<void>>(
() async {
final Recorder recorder = recorderFactory();
final Runner runner = recorder.isTracingEnabled && !_client.isInManualMode
final runner = recorder.isTracingEnabled && !_client.isInManualMode
? Runner(
recorder: recorder,
setUpAllDidRun: () => _client.startPerformanceTracing(benchmarkName),
@ -178,7 +178,7 @@ Future<void> _runBenchmark(String benchmarkName) async {
extension WebHTMLElementExtension on web.HTMLElement {
void appendHtml(String html) {
final web.HTMLDivElement div = web.document.createElement('div') as web.HTMLDivElement;
final div = web.document.createElement('div') as web.HTMLDivElement;
div.innerHTML = html.toJS;
final web.DocumentFragment fragment = web.document.createDocumentFragment();
fragment.append(div as JSAny);
@ -285,7 +285,7 @@ class TimeseriesVisualization {
final double barWidth = _screenWidth / _stats.samples.length;
double xOffset = 0;
for (int i = 0; i < _stats.samples.length; i++) {
for (var i = 0; i < _stats.samples.length; i++) {
final AnnotatedSample sample = _stats.samples[i];
if (sample.isWarmUpValue) {
@ -471,8 +471,8 @@ class LocalBenchmarkServerClient {
Map<String, String>? requestHeaders,
dynamic sendData,
}) {
final Completer<web.XMLHttpRequest> completer = Completer<web.XMLHttpRequest>();
final web.XMLHttpRequest xhr = web.XMLHttpRequest();
final completer = Completer<web.XMLHttpRequest>();
final xhr = web.XMLHttpRequest();
method ??= 'GET';
xhr.open(method, '$url', true);

View File

@ -25,7 +25,7 @@ void main() {
await Future<void>.delayed(const Duration(milliseconds: 500));
}
for (int i = 0; i < 3; i += 1) {
for (var i = 0; i < 3; i += 1) {
await scrollOnce(-300.0);
await scrollOnce(-300.0);
await scrollOnce(300.0);

View File

@ -45,8 +45,7 @@ void macroPerfTestMultiPageE2E(
}) {
final WidgetsBinding widgetsBinding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
assert(widgetsBinding is IntegrationTestWidgetsFlutterBinding);
final IntegrationTestWidgetsFlutterBinding binding =
widgetsBinding as IntegrationTestWidgetsFlutterBinding;
final binding = widgetsBinding as IntegrationTestWidgetsFlutterBinding;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
testWidgets(
@ -62,7 +61,7 @@ void macroPerfTestMultiPageE2E(
// See: https://github.com/flutter/flutter/issues/19434
await tester.binding.delayed(const Duration(microseconds: 250));
for (final ScrollableButtonRoute route in routes) {
for (final route in routes) {
expect(route.listViewKey, startsWith('/'));
expect(route.buttonKey, startsWith('/'));

View File

@ -26,7 +26,7 @@ void main() {
await Future<void>.delayed(const Duration(milliseconds: 500));
}
for (int i = 0; i < 2; i += 1) {
for (var i = 0; i < 2; i += 1) {
await scrollOnce(-3000.0);
await scrollOnce(-3000.0);
await scrollOnce(3000.0);

View File

@ -14,7 +14,7 @@ import 'package:macrobenchmarks/src/animated_image.dart';
/// passes a callback. This way, we can make sure to consistently wait for a
/// set number of image frames to render.
Future<void> main() async {
final Completer<void> waiter = Completer<void>();
final waiter = Completer<void>();
enableFlutterDriverExtension(
handler: (String? request) async {
if (request != 'waitForAnimation') {

View File

@ -6,7 +6,7 @@ import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
Future<void> main() async {
const String fileName = 'animated_image';
const fileName = 'animated_image';
test('Animate for 250 frames', () async {
final FlutterDriver driver = await FlutterDriver.connect();
@ -15,7 +15,7 @@ Future<void> main() async {
final Timeline timeline = await driver.traceAction(() async {
await driver.requestData('waitForAnimation');
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(fileName, pretty: true);
await driver.close();

View File

@ -6,7 +6,7 @@ import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
Future<void> main() async {
const String fileName = 'large_image_changer';
const fileName = 'large_image_changer';
test('Animate for 20 seconds', () async {
final FlutterDriver driver = await FlutterDriver.connect();
@ -33,7 +33,7 @@ Future<void> main() async {
}
if (timeline != null) {
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(fileName, pretty: true);
}

View File

@ -19,7 +19,7 @@ void main() {
await Future<void>.delayed(const Duration(milliseconds: 500));
}
for (int i = 0; i < 3; i += 1) {
for (var i = 0; i < 3; i += 1) {
await scrollOnce(-600.0);
await scrollOnce(-600.0);
await scrollOnce(600.0);

View File

@ -19,7 +19,7 @@ void main() {
await Future<void>.delayed(const Duration(milliseconds: 500));
}
for (int i = 0; i < 3; i += 1) {
for (var i = 0; i < 3; i += 1) {
await scrollOnce(-600.0);
await scrollOnce(-600.0);
await scrollOnce(600.0);

View File

@ -22,7 +22,7 @@ void main() {
// When we eventually add more test panes we will want to tweak these
// to go through all the panes
for (int i = 0; i < 6; i += 1) {
for (var i = 0; i < 6; i += 1) {
await scrollOnce(-300.0);
await scrollOnce(300.0);
}

View File

@ -20,7 +20,7 @@ void main() {
await Future<void>.delayed(const Duration(milliseconds: 500));
}
for (int i = 0; i < 3; i += 1) {
for (var i = 0; i < 3; i += 1) {
await scrollOnce(-300.0);
await scrollOnce(-300.0);
await scrollOnce(300.0);

View File

@ -26,7 +26,7 @@ Future<void> runDriverTestForRoute(String routeName, DriverTestCallBack body) as
// -320 comes from the logical pixels for a full screen scroll for the
// smallest reference device, iPhone 4, whose physical screen dimensions are
// 960px × 640px.
const double dyScroll = -320.0;
const dyScroll = -320.0;
await driver.scrollUntilVisible(scrollable, button, dyScroll: dyScroll);
await driver.tap(button);
@ -56,7 +56,7 @@ void macroPerfTest(
}
timeline = await driver.traceAction(() async {
final Future<void> durationFuture = Future<void>.delayed(duration);
final durationFuture = Future<void>.delayed(duration);
if (driverOps != null) {
await driverOps(driver);
}
@ -66,7 +66,7 @@ void macroPerfTest(
expect(timeline, isNotNull);
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(testName, pretty: true);
}, timeout: Timeout.none);
}

View File

@ -42,8 +42,8 @@ Future<void> main() async {
// BenchmarkingBinding is used by animation_bench, providing a simple
// stopwatch interface over rendering. Lifting it here makes all
// benchmarks run together.
final BenchmarkingBinding binding = BenchmarkingBinding();
final List<Benchmark> benchmarks = <Benchmark>[
final binding = BenchmarkingBinding();
final benchmarks = <Benchmark>[
('foundation/change_notifier_bench.dart', change_notifier_bench.execute),
('foundation/clamp.dart', clamp.execute),
('foundation/platform_asset_bundle.dart', platform_asset_bundle.execute),
@ -78,7 +78,7 @@ Future<void> main() async {
// Parses the optional compile-time dart variables; we can't have
// arguments passed in to main.
final ArgParser parser = ArgParser();
final parser = ArgParser();
final List<String> allowed = benchmarks.map((Benchmark e) => e.$1).toList();
parser.addMultiOption(
'tests',
@ -88,13 +88,13 @@ Future<void> main() async {
help: 'selected tests to run',
);
parser.addOption('seed', defaultsTo: '12345', help: 'selects seed to sort tests by');
final List<String> mainArgs = <String>[];
const String testArgs = String.fromEnvironment('tests');
final mainArgs = <String>[];
const testArgs = String.fromEnvironment('tests');
if (testArgs.isNotEmpty) {
mainArgs.addAll(<String>['--tests', testArgs]);
print('╡ ••• environment test override: $testArgs ••• ╞');
}
const String seedArgs = String.fromEnvironment('seed');
const seedArgs = String.fromEnvironment('seed');
if (seedArgs.isNotEmpty) {
mainArgs.addAll(<String>['--seed', seedArgs]);
print('╡ ••• environment seed override: $seedArgs ••• ╞');
@ -111,7 +111,7 @@ Future<void> main() async {
tests.shuffle(Random(int.parse(results.option('seed')!)));
print('╡ ••• Running microbenchmarks ••• ╞');
for (final Benchmark mark in tests) {
for (final mark in tests) {
// Reset the frame policy to default - each test can set it on their own.
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fadePointers;
print('╡ ••• Running ${mark.$1} ••• ╞');

View File

@ -13,8 +13,8 @@ double _doNormal({required double mean, required double stddev, required double
double _doMean(List<double> values) => values.reduce((double x, double y) => x + y) / values.length;
double _doStddev(List<double> values, double mean) {
double stddev = 0.0;
for (final double value in values) {
var stddev = 0.0;
for (final value in values) {
stddev += (value - mean) * (value - mean);
}
return math.sqrt(stddev / values.length);
@ -26,7 +26,7 @@ double _doIntegral({
required double stop,
required double resolution,
}) {
double result = 0.0;
var result = 0.0;
while (start < stop) {
final double value = func(start);
result += resolution * value;
@ -94,7 +94,7 @@ class BenchmarkResultPrinter {
}) {
final double mean = _doMean(values);
final double stddev = _doStddev(values, mean);
const double margin = 0.05;
const margin = 0.05;
final double probability = _doProbability(mean: mean, stddev: stddev, margin: margin);
_results.add(_BenchmarkResult(description, mean, unit, name));
_results.add(
@ -111,9 +111,9 @@ class BenchmarkResultPrinter {
/// for computer consumption and once formatted as plain text for humans.
void printToStdout() {
// IMPORTANT: keep these values in sync with dev/devicelab/bin/tasks/microbenchmarks.dart
const String jsonStart = '================ RESULTS ================';
const String jsonEnd = '================ FORMATTED ==============';
const String jsonPrefix = ':::JSON:::';
const jsonStart = '================ RESULTS ================';
const jsonEnd = '================ FORMATTED ==============';
const jsonPrefix = ':::JSON:::';
print(jsonStart);
print('$jsonPrefix ${_printJson()}');
@ -122,7 +122,7 @@ class BenchmarkResultPrinter {
}
String _printJson() {
final Map<String, double> results = <String, double>{};
final results = <String, double>{};
for (final _BenchmarkResult result in _results) {
results[result.name] = result.value;
}
@ -130,7 +130,7 @@ class BenchmarkResultPrinter {
}
String _printPlainText() {
final StringBuffer buf = StringBuffer();
final buf = StringBuffer();
for (final _BenchmarkResult result in _results) {
buf.writeln('${result.description}: ${result.value.toStringAsFixed(1)} ${result.unit}');
}

View File

@ -47,11 +47,11 @@ Future<void> execute() async {
]);
// Wait for frame rendering to stabilize.
for (int i = 0; i < 5; i++) {
for (var i = 0; i < 5; i++) {
await SchedulerBinding.instance.endOfFrame;
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
print('flutter_test allElements benchmark... (${WidgetsBinding.instance.rootElement})');
// Make sure we get enough elements to process for consistent benchmark runs
@ -69,7 +69,7 @@ Future<void> execute() async {
print('element count: $elementCount');
watch.start();
for (int i = 0; i < _kNumIters; i += 1) {
for (var i = 0; i < _kNumIters; i += 1) {
final List<Element> allElements = collectAllElementsFrom(
WidgetsBinding.instance.rootElement!,
skipOffstage: false,
@ -78,7 +78,7 @@ Future<void> execute() async {
}
watch.stop();
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'All elements iterate',
value: watch.elapsedMicroseconds / _kNumIters,

View File

@ -18,21 +18,17 @@ Future<void> execute() async {
// GC'ed in the end.
// Not removing listeners would cause memory leaks in a real application.
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
void runAddListenerBenchmark(int iteration, {bool addResult = true}) {
const String name = 'add';
for (int listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final List<_Notifier> notifiers = List<_Notifier>.generate(
iteration,
(_) => _Notifier(),
growable: false,
);
const name = 'add';
for (var listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final notifiers = List<_Notifier>.generate(iteration, (_) => _Notifier(), growable: false);
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < iteration; i += 1) {
for (int l = 0; l < listenerCount; l += 1) {
for (var i = 0; i < iteration; i += 1) {
for (var l = 0; l < listenerCount; l += 1) {
notifiers[i].addListener(() {});
}
}
@ -51,16 +47,16 @@ Future<void> execute() async {
}
void runNotifyListenerBenchmark(int iteration, {bool addResult = true}) {
const String name = 'notify';
const name = 'notify';
for (int listenerCount = 0; listenerCount <= 5; listenerCount += 1) {
final _Notifier notifier = _Notifier();
for (int i = 1; i <= listenerCount; i += 1) {
for (var listenerCount = 0; listenerCount <= 5; listenerCount += 1) {
final notifier = _Notifier();
for (var i = 1; i <= listenerCount; i += 1) {
notifier.addListener(() {});
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < iteration; i += 1) {
for (var i = 0; i < iteration; i += 1) {
notifier.notify();
}
watch.stop();
@ -78,21 +74,21 @@ Future<void> execute() async {
}
void runRemoveListenerBenchmark(int iteration, {bool addResult = true}) {
const String name = 'remove';
final List<VoidCallback> listeners = <VoidCallback>[() {}, () {}, () {}, () {}, () {}];
for (int listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final List<_Notifier> notifiers = List<_Notifier>.generate(iteration, (_) {
final _Notifier notifier = _Notifier();
for (int l = 0; l < listenerCount; l += 1) {
const name = 'remove';
final listeners = <VoidCallback>[() {}, () {}, () {}, () {}, () {}];
for (var listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final notifiers = List<_Notifier>.generate(iteration, (_) {
final notifier = _Notifier();
for (var l = 0; l < listenerCount; l += 1) {
notifier.addListener(listeners[l]);
}
return notifier;
}, growable: false);
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < iteration; i += 1) {
for (int l = 0; l < listenerCount; l += 1) {
for (var i = 0; i < iteration; i += 1) {
for (var l = 0; l < listenerCount; l += 1) {
notifiers[i].removeListener(listeners[l]);
}
}
@ -111,28 +107,28 @@ Future<void> execute() async {
}
void runRemoveListenerWhileNotifyingBenchmark(int iteration, {bool addResult = true}) {
const String name = 'removeWhileNotify';
const name = 'removeWhileNotify';
final List<VoidCallback> listeners = <VoidCallback>[() {}, () {}, () {}, () {}, () {}];
for (int listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final List<_Notifier> notifiers = List<_Notifier>.generate(iteration, (_) {
final _Notifier notifier = _Notifier();
final listeners = <VoidCallback>[() {}, () {}, () {}, () {}, () {}];
for (var listenerCount = 1; listenerCount <= 5; listenerCount += 1) {
final notifiers = List<_Notifier>.generate(iteration, (_) {
final notifier = _Notifier();
notifier.addListener(() {
// This listener will remove all other listeners. So that only this
// one is called and measured.
for (int l = 0; l < listenerCount; l += 1) {
for (var l = 0; l < listenerCount; l += 1) {
notifier.removeListener(listeners[l]);
}
});
for (int l = 0; l < listenerCount; l += 1) {
for (var l = 0; l < listenerCount; l += 1) {
notifier.addListener(listeners[l]);
}
return notifier;
}, growable: false);
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < iteration; i += 1) {
for (var i = 0; i < iteration; i += 1) {
notifiers[i].notify();
}
watch.stop();

View File

@ -11,16 +11,16 @@ const int _kNumIterations = 1000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
{
final List<double> clampDoubleValues = <double>[];
for (int j = 0; j < _kNumIterations; ++j) {
final clampDoubleValues = <double>[];
for (var j = 0; j < _kNumIterations; ++j) {
double tally = 0;
watch.reset();
watch.start();
for (int i = 0; i < _kBatchSize; i += 1) {
for (var i = 0; i < _kBatchSize; i += 1) {
tally += clampDouble(-1.0, 0.0, 1.0);
tally += clampDouble(2.0, 0.0, 1.0);
tally += clampDouble(0.0, 0.0, 1.0);
@ -42,13 +42,13 @@ Future<void> execute() async {
}
{
final List<double> doubleClampValues = <double>[];
final doubleClampValues = <double>[];
for (int j = 0; j < _kNumIterations; ++j) {
for (var j = 0; j < _kNumIterations; ++j) {
double tally = 0;
watch.reset();
watch.start();
for (int i = 0; i < _kBatchSize; i += 1) {
for (var i = 0; i < _kBatchSize; i += 1) {
tally += -1.0.clamp(0.0, 1.0);
tally += 2.0.clamp(0.0, 1.0);
tally += 0.0.clamp(0.0, 1.0);

View File

@ -12,13 +12,13 @@ const int _kNumIterations = 1000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
WidgetsFlutterBinding.ensureInitialized();
final Stopwatch watch = Stopwatch();
final PlatformAssetBundle bundle = rootBundle as PlatformAssetBundle;
final watch = Stopwatch();
final bundle = rootBundle as PlatformAssetBundle;
watch.start();
for (int i = 0; i < _kNumIterations; i++) {
for (var i = 0; i < _kNumIterations; i++) {
await AssetManifest.loadFromAssetBundle(bundle);
bundle.clear();
}

View File

@ -22,23 +22,23 @@ class TestAnimationController extends AnimationController {
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
void runNotifyListenersLoopWithObserverList(
int totalIterations, {
bool failRemoval = false,
bool addResult = true,
}) {
final String suffix = failRemoval ? 'removalFail' : 'removalSuccess';
final String name = 'notifyListeners:ObserverList:$suffix';
final suffix = failRemoval ? 'removalFail' : 'removalSuccess';
final name = 'notifyListeners:ObserverList:$suffix';
void miss() {}
for (final int callbackCount in callbackCounts) {
final int iterations = totalIterations ~/ callbackCount;
final ObserverList<VoidCallback> observerList = ObserverList<VoidCallback>();
for (int i = 0; i < callbackCount; ++i) {
final observerList = ObserverList<VoidCallback>();
for (var i = 0; i < callbackCount; ++i) {
observerList.add(switch (failRemoval) {
false => () {
final VoidCallback first = (observerList.iterator..moveNext()).current;
@ -50,11 +50,11 @@ Future<void> execute() async {
});
}
final Stopwatch watch = Stopwatch()..start();
final watch = Stopwatch()..start();
for (int i = 0; i < iterations; ++i) {
for (var i = 0; i < iterations; ++i) {
final List<VoidCallback> list = observerList.toList(growable: false);
for (final VoidCallback cb in list) {
for (final cb in list) {
if (observerList.contains(cb)) {
cb();
}
@ -75,13 +75,13 @@ Future<void> execute() async {
}
void runNotifyListenersLoopWithHashedObserverList(int totalIterations, {bool addResult = true}) {
const String name = 'notifyListeners:HashedObserverList';
const name = 'notifyListeners:HashedObserverList';
for (final int callbackCount in callbackCounts) {
final int iterations = totalIterations ~/ callbackCount;
final HashedObserverList<VoidCallback> observerList = HashedObserverList<VoidCallback>();
for (int i = 0; i < callbackCount; ++i) {
final observerList = HashedObserverList<VoidCallback>();
for (var i = 0; i < callbackCount; ++i) {
observerList.add(() {
final VoidCallback first = (observerList.iterator..moveNext()).current;
@ -90,11 +90,11 @@ Future<void> execute() async {
});
}
final Stopwatch watch = Stopwatch()..start();
final watch = Stopwatch()..start();
for (int i = 0; i < iterations; ++i) {
for (var i = 0; i < iterations; ++i) {
final List<VoidCallback> list = observerList.toList(growable: false);
for (final VoidCallback cb in list) {
for (final cb in list) {
if (observerList.contains(cb)) {
cb();
}
@ -115,13 +115,13 @@ Future<void> execute() async {
}
void runNotifyListenersLoopWithAnimationController(int totalIterations, {bool addResult = true}) {
const String name = 'notifyListeners:AnimationController';
const name = 'notifyListeners:AnimationController';
for (final int callbackCount in callbackCounts) {
final int iterations = totalIterations ~/ callbackCount;
final TestAnimationController controller = TestAnimationController();
for (int i = 0; i < callbackCount; ++i) {
final controller = TestAnimationController();
for (var i = 0; i < callbackCount; ++i) {
late final VoidCallback cb;
cb = () {
controller.removeListener(cb);
@ -130,9 +130,9 @@ Future<void> execute() async {
controller.addListener(cb);
}
final Stopwatch watch = Stopwatch()..start();
final watch = Stopwatch()..start();
for (int i = 0; i < iterations; ++i) {
for (var i = 0; i < iterations; ++i) {
controller.notifyListeners();
}

View File

@ -12,17 +12,17 @@ const int _kNumIterations = 100;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
WidgetsFlutterBinding.ensureInitialized();
final Stopwatch watch = Stopwatch();
final PlatformAssetBundle bundle = PlatformAssetBundle();
final watch = Stopwatch();
final bundle = PlatformAssetBundle();
final List<double> values = <double>[];
for (int j = 0; j < _kNumIterations; ++j) {
final values = <double>[];
for (var j = 0; j < _kNumIterations; ++j) {
double tally = 0;
watch.reset();
watch.start();
for (int i = 0; i < _kBatchSize; i += 1) {
for (var i = 0; i < _kBatchSize; i += 1) {
// We don't load images like this. PlatformAssetBundle is used for
// other assets (like Rive animations). We are using an image because it's
// conveniently sized and available for the test.

View File

@ -10,12 +10,12 @@ const int _kNumIterations = 100000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const StandardMessageCodec codec = StandardMessageCodec();
final Stopwatch watch = Stopwatch();
const codec = StandardMessageCodec();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage(null);
}
watch.stop();
@ -29,7 +29,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage(12345);
}
watch.stop();
@ -44,7 +44,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage('This is a performance test.');
}
watch.stop();
@ -58,7 +58,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage(<Object>[1234, 'This is a performance test.', 1.25, true]);
}
watch.stop();
@ -72,7 +72,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage(<String, Object>{
'integer': 1234,
'string': 'This is a performance test.',
@ -92,7 +92,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMessage('special chars >\u263A\u{1F602}<');
}
watch.stop();

View File

@ -10,13 +10,13 @@ const int _kNumIterations = 100000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const StandardMethodCodec codec = StandardMethodCodec();
final Stopwatch watch = Stopwatch();
const String methodName = 'something';
const codec = StandardMethodCodec();
final watch = Stopwatch();
const methodName = 'something';
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMethodCall(const MethodCall(methodName));
}
watch.stop();
@ -30,7 +30,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMethodCall(const MethodCall(methodName, 12345));
}
watch.stop();
@ -45,7 +45,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMethodCall(const MethodCall(methodName, 'This is a performance test.'));
}
watch.stop();
@ -59,7 +59,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMethodCall(
const MethodCall(methodName, <Object>[1234, 'This is a performance test.', 1.25, true]),
);
@ -75,7 +75,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
codec.encodeMethodCall(
const MethodCall(methodName, <String, Object>{
'integer': 1234,

View File

@ -10,11 +10,11 @@ const int _kNumIterations = 10000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
FlutterTimeline.startSync('foo');
FlutterTimeline.finishSync();
}
@ -29,7 +29,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
FlutterTimeline.startSync(
'foo',
arguments: <String, dynamic>{

View File

@ -14,10 +14,10 @@ void _testCurve(
required String description,
required BenchmarkResultPrinter printer,
}) {
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
print('$description benchmark...');
watch.start();
for (int i = 0; i < _kNumIters; i += 1) {
for (var i = 0; i < _kNumIters; i += 1) {
final double t = i / _kNumIters.toDouble();
curve.transform(t);
}
@ -33,7 +33,7 @@ void _testCurve(
void main() {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
_testCurve(
const Cubic(0.0, 0.25, 0.5, 1.0),
name: 'cubic_animation_transform_iteration',
@ -41,7 +41,7 @@ void main() {
printer: printer,
);
final CatmullRomCurve catmullRomCurve = CatmullRomCurve(const <Offset>[
final catmullRomCurve = CatmullRomCurve(const <Offset>[
Offset(0.09, 0.99),
Offset(0.21, 0.01),
Offset(0.28, 0.99),

View File

@ -23,7 +23,7 @@ Future<void> execute() async {
);
}
final List<Matrix4> affineTransforms = <Matrix4>[
final affineTransforms = <Matrix4>[
Matrix4.identity()
..scale(1.2, 1.3, 1.0)
..rotateZ(0.1),
@ -32,19 +32,19 @@ Future<void> execute() async {
..scale(1.2, 1.3, 1.0)
..translate(12.0, 13.0, 10.0),
];
final List<Matrix4> perspectiveTransforms = <Matrix4>[
final perspectiveTransforms = <Matrix4>[
makePerspective(10.0, math.pi / 8.0, 0.3),
makePerspective(8.0, math.pi / 8.0, 0.2),
makePerspective(1.0, math.pi / 4.0, 0.1)..rotateX(0.1),
];
final List<Rect> rectangles = <Rect>[
final rectangles = <Rect>[
const Rect.fromLTRB(1.1, 1.2, 1.5, 1.8),
const Rect.fromLTRB(1.1, 1.2, 0.0, 1.0),
const Rect.fromLTRB(1.1, 1.2, 1.3, 1.0),
const Rect.fromLTRB(-1.1, -1.2, 0.0, 1.0),
const Rect.fromLTRB(-1.1, -1.2, -1.5, -1.8),
];
final List<Offset> offsets = <Offset>[
final offsets = <Offset>[
const Offset(1.1, 1.2),
const Offset(1.5, 1.8),
Offset.zero,
@ -57,14 +57,14 @@ Future<void> execute() async {
final int nOffsets = offsets.length;
// Warm up lap
for (int i = 0; i < _kNumWarmUp; i += 1) {
for (var i = 0; i < _kNumWarmUp; i += 1) {
final Matrix4 transform = perspectiveTransforms[i % nPerspective];
final Rect rect = rectangles[(i ~/ nPerspective) % nRectangles];
final Offset offset = offsets[(i ~/ nPerspective) % nOffsets];
MatrixUtils.transformRect(transform, rect);
MatrixUtils.transformPoint(transform, offset);
}
for (int i = 0; i < _kNumWarmUp; i += 1) {
for (var i = 0; i < _kNumWarmUp; i += 1) {
final Matrix4 transform = affineTransforms[i % nAffine];
final Rect rect = rectangles[(i ~/ nAffine) % nRectangles];
final Offset offset = offsets[(i ~/ nAffine) % nOffsets];
@ -72,9 +72,9 @@ Future<void> execute() async {
MatrixUtils.transformPoint(transform, offset);
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
final Matrix4 transform = perspectiveTransforms[i % nPerspective];
final Rect rect = rectangles[(i ~/ nPerspective) % nRectangles];
MatrixUtils.transformRect(transform, rect);
@ -84,7 +84,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
final Matrix4 transform = affineTransforms[i % nAffine];
final Rect rect = rectangles[(i ~/ nAffine) % nRectangles];
MatrixUtils.transformRect(transform, rect);
@ -94,7 +94,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
final Matrix4 transform = perspectiveTransforms[i % nPerspective];
final Offset offset = offsets[(i ~/ nPerspective) % nOffsets];
MatrixUtils.transformPoint(transform, offset);
@ -104,7 +104,7 @@ Future<void> execute() async {
watch.reset();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
final Matrix4 transform = affineTransforms[i % nAffine];
final Offset offset = offsets[(i ~/ nAffine) % nOffsets];
MatrixUtils.transformPoint(transform, offset);
@ -112,7 +112,7 @@ Future<void> execute() async {
watch.stop();
final int pointMicrosecondsAffine = watch.elapsedMicroseconds;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const double scale = 1000.0 / _kNumIterations;
printer.addResult(
description: 'MatrixUtils.transformRectPerspective',

View File

@ -10,16 +10,16 @@ const int _kNumIters = 10000;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
print('RRect contains benchmark...');
watch.start();
for (int i = 0; i < _kNumIters; i += 1) {
final RRect outer = RRect.fromLTRBR(10, 10, 20, 20, const Radius.circular(2.0));
for (var i = 0; i < _kNumIters; i += 1) {
final outer = RRect.fromLTRBR(10, 10, 20, 20, const Radius.circular(2.0));
outer.contains(const Offset(15, 15));
}
watch.stop();
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'RRect contains',
value: watch.elapsedMicroseconds / _kNumIters,

View File

@ -12,7 +12,7 @@ const int _kNumIters = 300;
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
print('GestureDetector semantics benchmark...');
await benchmarkWidgets((WidgetTester tester) async {
@ -28,19 +28,19 @@ Future<void> execute() async {
// Warm up runs get the app into steady state, making benchmark
// results more credible
for (int i = 0; i < _kNumWarmUpIters; i += 1) {
for (var i = 0; i < _kNumWarmUpIters; i += 1) {
await iter();
}
await tester.pumpAndSettle();
watch.start();
for (int i = 0; i < _kNumIters; i += 1) {
for (var i = 0; i < _kNumIters; i += 1) {
await iter();
}
watch.stop();
}, semanticsEnabled: true);
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'GestureDetector',
value: watch.elapsedMicroseconds / _kNumIters,

View File

@ -19,8 +19,8 @@ class TrackerBenchmark {
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final List<TrackerBenchmark> benchmarks = <TrackerBenchmark>[
final printer = BenchmarkResultPrinter();
final benchmarks = <TrackerBenchmark>[
TrackerBenchmark(
name: 'velocity_tracker_iteration',
tracker: VelocityTracker.withKind(PointerDeviceKind.touch),
@ -30,15 +30,15 @@ Future<void> execute() async {
tracker: IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch),
),
];
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
await benchmarkWidgets((WidgetTester tester) async {
for (final TrackerBenchmark benchmark in benchmarks) {
for (final benchmark in benchmarks) {
print('${benchmark.name} benchmark...');
final VelocityTracker tracker = benchmark.tracker;
watch.reset();
watch.start();
for (int i = 0; i < _kNumIters; i += 1) {
for (var i = 0; i < _kNumIters; i += 1) {
for (final PointerEvent event in velocityEventData) {
if (event is PointerDownEvent || event is PointerMoveEvent) {
tracker.addPosition(event.timeStamp, event.position);

View File

@ -26,18 +26,18 @@ Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
// Warm up lap
for (int i = 0; i < _kNumWarmUp; i += 1) {
for (var i = 0; i < _kNumWarmUp; i += 1) {
await compute(test, 10);
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
await compute(test, 1000000);
}
final int elapsedMicroseconds = watch.elapsedMicroseconds;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const double scale = 1000.0 / _kNumIterations;
printer.addResult(
description: 'compute',

View File

@ -11,29 +11,29 @@ Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
// Warm up lap
for (int i = 0; i < _kNumWarmUp; i += 1) {
for (var i = 0; i < _kNumWarmUp; i += 1) {
sumIterable(generateIterableSyncStar());
sumIterable(generateIterableList());
sumIterable(Iterable<int>.generate(100, generate));
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
sumIterable(generateIterableSyncStar());
}
final int traverseIterableSyncStar = watch.elapsedMicroseconds;
watch
..reset()
..start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
sumIterable(generateIterableList());
}
final int traverseIterableList = watch.elapsedMicroseconds;
watch
..reset()
..start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
sumIterable(Iterable<int>.generate(100, generate));
}
final int traverseIterableGenerated = watch.elapsedMicroseconds;
@ -41,7 +41,7 @@ Future<void> execute() async {
..reset()
..start();
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const double scale = 1000.0 / _kNumIterations;
printer.addResult(
description: 'traverseIterableSyncStar',
@ -68,23 +68,23 @@ int generate(int index) => index;
// Generate an Iterable using a sync* method.
Iterable<int> generateIterableSyncStar() sync* {
for (int i = 0; i < 100; i++) {
for (var i = 0; i < 100; i++) {
yield i;
}
}
// Generate an Iterable using a List.
Iterable<int> generateIterableList() {
final List<int> items = <int>[];
for (int i = 0; i < 100; i++) {
final items = <int>[];
for (var i = 0; i < 100; i++) {
items.add(i);
}
return items;
}
int sumIterable(Iterable<int> values) {
int result = 0;
for (final int value in values) {
var result = 0;
for (final value in values) {
result += value;
}
return result;

View File

@ -17,8 +17,8 @@ Future<void> execute() async {
' printer took a galley of type and scrambled it to make a'
' type specimen book'
.split(' ');
final List<InlineSpanSemanticsInformation> data = <InlineSpanSemanticsInformation>[];
for (int i = 0; i < words.length; i++) {
final data = <InlineSpanSemanticsInformation>[];
for (var i = 0; i < words.length; i++) {
if (i.isEven) {
data.add(InlineSpanSemanticsInformation(words[i]));
} else if (i.isEven) {
@ -28,21 +28,21 @@ Future<void> execute() async {
print(words);
// Warm up lap
for (int i = 0; i < _kNumWarmUp; i += 1) {
for (var i = 0; i < _kNumWarmUp; i += 1) {
combineSemanticsInfoSyncStar(data);
combineSemanticsInfoList(data);
}
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
consumeSpan(combineSemanticsInfoSyncStar(data));
}
final int combineSemanticsInfoSyncStarTime = watch.elapsedMicroseconds;
watch
..reset()
..start();
for (int i = 0; i < _kNumIterations; i += 1) {
for (var i = 0; i < _kNumIterations; i += 1) {
consumeSpan(combineSemanticsInfoList(data));
}
final int combineSemanticsInfoListTime = watch.elapsedMicroseconds;
@ -50,7 +50,7 @@ Future<void> execute() async {
..reset()
..start();
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
const double scale = 1000.0 / _kNumIterations;
printer.addResult(
description: 'combineSemanticsInfoSyncStar',
@ -68,8 +68,8 @@ Future<void> execute() async {
}
String consumeSpan(Iterable<InlineSpanSemanticsInformation> items) {
String result = '';
for (final InlineSpanSemanticsInformation span in items) {
var result = '';
for (final span in items) {
result += span.text;
}
return result;
@ -78,9 +78,9 @@ String consumeSpan(Iterable<InlineSpanSemanticsInformation> items) {
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(
List<InlineSpanSemanticsInformation> inputs,
) sync* {
String workingText = '';
var workingText = '';
String? workingLabel;
for (final InlineSpanSemanticsInformation info in inputs) {
for (final info in inputs) {
if (info.requiresOwnNode) {
yield InlineSpanSemanticsInformation(
workingText,
@ -102,10 +102,10 @@ Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoSyncStar(
Iterable<InlineSpanSemanticsInformation> combineSemanticsInfoList(
List<InlineSpanSemanticsInformation> inputs,
) {
String workingText = '';
var workingText = '';
String? workingLabel;
final List<InlineSpanSemanticsInformation> result = <InlineSpanSemanticsInformation>[];
for (final InlineSpanSemanticsInformation info in inputs) {
final result = <InlineSpanSemanticsInformation>[];
for (final info in inputs) {
if (info.requiresOwnNode) {
result.add(
InlineSpanSemanticsInformation(workingText, semanticsLabel: workingLabel ?? workingText),

View File

@ -21,25 +21,18 @@ Future<void> execute() async {
// We control the framePolicy below to prevent us from scheduling frames in
// the engine, so that the engine does not interfere with our timings.
final LiveTestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final binding = TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final Stopwatch watch = Stopwatch();
int iterations = 0;
final watch = Stopwatch();
var iterations = 0;
await benchmarkWidgets((WidgetTester tester) async {
runApp(intrinsicTextHeight);
// Wait for the UI to stabilize.
await tester.pumpAndSettle(const Duration(seconds: 1));
final TestViewConfiguration big = TestViewConfiguration.fromView(
size: const Size(360.0, 640.0),
view: tester.view,
);
final TestViewConfiguration small = TestViewConfiguration.fromView(
size: const Size(100.0, 640.0),
view: tester.view,
);
final big = TestViewConfiguration.fromView(size: const Size(360.0, 640.0), view: tester.view);
final small = TestViewConfiguration.fromView(size: const Size(100.0, 640.0), view: tester.view);
final RenderView renderView = WidgetsBinding.instance.renderViews.single;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
@ -52,7 +45,7 @@ Future<void> execute() async {
watch.stop();
});
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'Text intrinsic height',
value: watch.elapsedMicroseconds / iterations,

View File

@ -16,21 +16,21 @@ Future<void> execute(BenchmarkingBinding binding) async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
stock_data.StockData.actuallyFetchData = false;
final Stopwatch wallClockWatch = Stopwatch();
final wallClockWatch = Stopwatch();
int totalOpenFrameElapsedMicroseconds = 0;
int totalOpenIterationCount = 0;
int totalCloseFrameElapsedMicroseconds = 0;
int totalCloseIterationCount = 0;
int totalSubsequentFramesElapsedMicroseconds = 0;
int totalSubsequentFramesIterationCount = 0;
var totalOpenFrameElapsedMicroseconds = 0;
var totalOpenIterationCount = 0;
var totalCloseFrameElapsedMicroseconds = 0;
var totalCloseIterationCount = 0;
var totalSubsequentFramesElapsedMicroseconds = 0;
var totalSubsequentFramesIterationCount = 0;
await benchmarkWidgets((WidgetTester tester) async {
stocks.main();
await tester.pump(); // Start startup animation
await tester.pump(const Duration(seconds: 1)); // Complete startup animation
bool drawerIsOpen = false;
var drawerIsOpen = false;
wallClockWatch.start();
while (wallClockWatch.elapsed < kBenchmarkTime) {
binding.drawFrameWatch.reset();
@ -57,7 +57,7 @@ Future<void> execute(BenchmarkingBinding binding) async {
}
});
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'Stock animation',
value: wallClockWatch.elapsedMicroseconds / (1000 * 1000),

View File

@ -17,12 +17,11 @@ Future<List<double>> runBuildBenchmark() async {
// We control the framePolicy below to prevent us from scheduling frames in
// the engine, so that the engine does not interfere with our timings.
final LiveTestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final binding = TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final Stopwatch watch = Stopwatch();
int iterations = 0;
final List<double> values = <double>[];
final watch = Stopwatch();
var iterations = 0;
final values = <double>[];
await benchmarkWidgets((WidgetTester tester) async {
stocks.main();
@ -57,7 +56,7 @@ Future<List<double>> runBuildBenchmark() async {
}
Future<void> execute() async {
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResultStatistics(
description: 'Stock build',
values: await runBuildBenchmark(),

View File

@ -10,7 +10,7 @@ import 'build_bench.dart';
Future<void> execute() async {
debugProfileBuildsEnabledUserWidgets = true;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResultStatistics(
description: 'Stock build User Widgets Profiled',
values: await runBuildBenchmark(),

View File

@ -18,11 +18,10 @@ Future<void> execute() async {
// We control the framePolicy below to prevent us from scheduling frames in
// the engine, so that the engine does not interfere with our timings.
final LiveTestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final binding = TestWidgetsFlutterBinding.ensureInitialized() as LiveTestWidgetsFlutterBinding;
final Stopwatch watch = Stopwatch();
int iterations = 0;
final watch = Stopwatch();
var iterations = 0;
await benchmarkWidgets((WidgetTester tester) async {
stocks.main();
@ -32,14 +31,8 @@ Future<void> execute() async {
await tester.pump(); // Start drawer animation
await tester.pump(const Duration(seconds: 1)); // Complete drawer animation
final TestViewConfiguration big = TestViewConfiguration.fromView(
size: const Size(360.0, 640.0),
view: tester.view,
);
final TestViewConfiguration small = TestViewConfiguration.fromView(
size: const Size(355.0, 635.0),
view: tester.view,
);
final big = TestViewConfiguration.fromView(size: const Size(360.0, 640.0), view: tester.view);
final small = TestViewConfiguration.fromView(size: const Size(355.0, 635.0), view: tester.view);
final RenderView renderView = WidgetsBinding.instance.renderViews.single;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmark;
@ -52,7 +45,7 @@ Future<void> execute() async {
watch.stop();
});
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'Stock layout',
value: watch.elapsedMicroseconds / iterations,

View File

@ -81,10 +81,10 @@ const List<String> assets = <String>[
Future<void> execute() async {
assert(false, "Don't run benchmarks in debug mode! Use 'flutter run --release'.");
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
await benchmarkWidgets((WidgetTester tester) async {
watch.start();
for (int i = 0; i < 10; i += 1) {
for (var i = 0; i < 10; i += 1) {
await Future.wait(<Future<ui.ImmutableBuffer>>[
for (final String asset in assets) rootBundle.loadBuffer(asset),
]);
@ -92,7 +92,7 @@ Future<void> execute() async {
watch.stop();
});
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
printer.addResult(
description: 'Image loading',
value: watch.elapsedMilliseconds.toDouble(),

View File

@ -41,7 +41,7 @@ class Sky extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final Rect rect = Offset.zero & size;
const RadialGradient gradient = RadialGradient(
const gradient = RadialGradient(
center: Alignment(0.7, -0.6),
radius: 0.2,
colors: <Color>[Color(0xFFFFFF00), Color(0xFF0099FF)],

View File

@ -28,9 +28,9 @@ List<Object?> _makeTestBuffer(int size) {
}
Future<double> _runBasicStandardSmall(BasicMessageChannel<Object?> basicStandard, int count) async {
final Stopwatch watch = Stopwatch();
final watch = Stopwatch();
watch.start();
for (int i = 0; i < count; ++i) {
for (var i = 0; i < count; ++i) {
await basicStandard.send(1234);
}
watch.stop();
@ -64,11 +64,11 @@ Future<double> _runBasicStandardParallel(
Object? payload,
int parallel,
) async {
final Stopwatch watch = Stopwatch();
final Completer<int> completer = Completer<int>();
final _Counter counter = _Counter();
final watch = Stopwatch();
final completer = Completer<int>();
final counter = _Counter();
watch.start();
for (int i = 0; i < parallel; ++i) {
for (var i = 0; i < parallel; ++i) {
basicStandard.send(payload).then((Object? result) {
_runBasicStandardParallelRecurse(basicStandard, counter, count, completer, payload);
});
@ -83,11 +83,11 @@ Future<double> _runBasicStandardLarge(
List<Object?> largeBuffer,
int count,
) async {
int size = 0;
final Stopwatch watch = Stopwatch();
var size = 0;
final watch = Stopwatch();
watch.start();
for (int i = 0; i < count; ++i) {
final List<Object?>? result = await basicStandard.send(largeBuffer) as List<Object?>?;
for (var i = 0; i < count; ++i) {
final result = await basicStandard.send(largeBuffer) as List<Object?>?;
// This check should be tiny compared to the actual channel send/receive.
size += (result == null) ? 0 : result.length;
}
@ -105,10 +105,10 @@ Future<double> _runBasicBinary(
ByteData buffer,
int count,
) async {
int size = 0;
final Stopwatch watch = Stopwatch();
var size = 0;
final watch = Stopwatch();
watch.start();
for (int i = 0; i < count; ++i) {
for (var i = 0; i < count; ++i) {
final ByteData? result = await basicBinary.send(buffer);
// This check should be tiny compared to the actual channel send/receive.
size += (result == null) ? 0 : result.lengthInBytes;
@ -146,29 +146,26 @@ Future<void> _runTests() async {
throw Exception("Must be run in profile mode! Use 'flutter run --profile'.");
}
const BasicMessageChannel<Object?> resetChannel = BasicMessageChannel<Object?>(
const resetChannel = BasicMessageChannel<Object?>(
'dev.flutter.echo.reset',
StandardMessageCodec(),
);
const BasicMessageChannel<Object?> basicStandard = BasicMessageChannel<Object?>(
const basicStandard = BasicMessageChannel<Object?>(
'dev.flutter.echo.basic.standard',
StandardMessageCodec(),
);
const BasicMessageChannel<ByteData> basicBinary = BasicMessageChannel<ByteData>(
'dev.flutter.echo.basic.binary',
BinaryCodec(),
);
const basicBinary = BasicMessageChannel<ByteData>('dev.flutter.echo.basic.binary', BinaryCodec());
/// WARNING: Don't change the following line of code, it will invalidate
/// `Large` tests. Instead make a different test. The size of largeBuffer
/// serialized is 14214 bytes.
final List<Object?> largeBuffer = _makeTestBuffer(1000);
final ByteData largeBufferBytes = const StandardMessageCodec().encodeMessage(largeBuffer)!;
final ByteData oneMB = ByteData(1024 * 1024);
final oneMB = ByteData(1024 * 1024);
const int numMessages = 2500;
const numMessages = 2500;
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
final printer = BenchmarkResultPrinter();
await _runTest(
test: (int x) => _runBasicStandardSmall(basicStandard, x),
resetChannel: resetChannel,
@ -210,7 +207,7 @@ Future<void> _runTests() async {
numMessages: numMessages,
);
// Background platform channels aren't yet implemented for iOS.
const BasicMessageChannel<Object?> backgroundStandard = BasicMessageChannel<Object?>(
const backgroundStandard = BasicMessageChannel<Object?>(
'dev.flutter.echo.background.standard',
StandardMessageCodec(),
);

View File

@ -54,7 +54,7 @@ class DummyPlatformView extends StatelessWidget {
@override
Widget build(BuildContext context) {
const String viewType = 'benchmarks/platform_views_layout/DummyPlatformView';
const viewType = 'benchmarks/platform_views_layout/DummyPlatformView';
late Widget nativeView;
if (Platform.isIOS) {
nativeView = const UiKitView(viewType: viewType);

View File

@ -23,10 +23,10 @@ class PlatformViewAppState extends State<PlatformViewApp> {
// Test IDs from Admob:
// https://developers.google.com/admob/ios/test-ads
// https://developers.google.com/admob/android/test-ads
final String bannerId = Platform.isAndroid
final bannerId = Platform.isAndroid
? 'ca-app-pub-3940256099942544/6300978111'
: 'ca-app-pub-3940256099942544/2934735716';
final BannerAd bannerAd = BannerAd(
final bannerAd = BannerAd(
adUnitId: bannerId,
request: const AdRequest(),
size: AdSize.banner,

View File

@ -23,10 +23,10 @@ class PlatformViewAppState extends State<PlatformViewApp> {
// Test IDs from Admob:
// https://developers.google.com/admob/ios/test-ads
// https://developers.google.com/admob/android/test-ads
final String bannerId = Platform.isAndroid
final bannerId = Platform.isAndroid
? 'ca-app-pub-3940256099942544/6300978111'
: 'ca-app-pub-3940256099942544/2934735716';
final BannerAd bannerAd = BannerAd(
final bannerAd = BannerAd(
adUnitId: bannerId,
request: const AdRequest(),
size: AdSize.banner,

View File

@ -56,7 +56,7 @@ class DummyPlatformView extends StatelessWidget {
@override
Widget build(BuildContext context) {
const String viewType = 'benchmarks/platform_views_layout/DummyPlatformView';
const viewType = 'benchmarks/platform_views_layout/DummyPlatformView';
late Widget nativeView;
if (Platform.isIOS) {
nativeView = const UiKitView(viewType: viewType);
@ -74,9 +74,9 @@ class ExpensivePainter extends CustomPainter {
void paint(Canvas canvas, Size size) {
final double boxWidth = size.width / 50;
final double boxHeight = size.height / 50;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
final Rect rect = Rect.fromLTWH(i * boxWidth, j * boxHeight, boxWidth, boxHeight);
for (var i = 0; i < 50; i++) {
for (var j = 0; j < 50; j++) {
final rect = Rect.fromLTWH(i * boxWidth, j * boxHeight, boxWidth, boxHeight);
canvas.drawRect(
rect,
Paint()

View File

@ -30,22 +30,22 @@ void main() {
// Find the scrollable stock list
final SerializableFinder list = find.byValueKey(listKey);
for (int j = 0; j < 5; j += 1) {
for (var j = 0; j < 5; j += 1) {
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -30,22 +30,22 @@ void main() {
// Find the scrollable stock list
final SerializableFinder list = find.byValueKey(listKey);
for (int j = 0; j < 5; j += 1) {
for (var j = 0; j < 5; j += 1) {
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -32,22 +32,22 @@ void main() {
// Find the scrollable stock list
final SerializableFinder list = find.byValueKey(listKey);
for (int j = 0; j < 5; j += 1) {
for (var j = 0; j < 5; j += 1) {
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -32,22 +32,22 @@ void main() {
// Find the scrollable stock list
final SerializableFinder list = find.byValueKey(listKey);
for (int j = 0; j < 5; j += 1) {
for (var j = 0; j < 5; j += 1) {
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

View File

@ -32,22 +32,22 @@ void main() {
// Find the scrollable stock list
final SerializableFinder list = find.byValueKey(listKey);
for (int j = 0; j < 5; j += 1) {
for (var j = 0; j < 5; j += 1) {
// Scroll down
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
// Scroll up
for (int i = 0; i < 5; i += 1) {
for (var i = 0; i < 5; i += 1) {
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
await Future<void>.delayed(const Duration(milliseconds: 500));
}
}
});
final TimelineSummary summary = TimelineSummary.summarize(timeline);
final summary = TimelineSummary.summarize(timeline);
await summary.writeTimelineToFile(summaryName, pretty: true);
}

Some files were not shown because too many files have changed in this diff Show More