flutter/dev/benchmarks/complex_layout/test_memory/scroll_perf.dart
Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

65 lines
2.2 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:complex_layout/src/app.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_test/flutter_test.dart';
/// The speed, in pixels per second, that the drag gestures should end with.
const double speed = 1500.0;
/// The number of down drags and the number of up drags. The total number of
/// gestures is twice this number.
const int maxIterations = 4;
/// The time that is allowed between gestures for the fling effect to settle.
const Duration pauses = Duration(milliseconds: 500);
Future<void> main() async {
final Completer<void> ready = Completer<void>();
runApp(
GestureDetector(
onTap: () {
debugPrint('==== MEMORY BENCHMARK ==== TAPPED ====');
ready.complete();
},
behavior: HitTestBehavior.opaque,
child: const IgnorePointer(child: ComplexLayoutApp()),
),
);
await SchedulerBinding.instance.endOfFrame;
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
await ready.future; // waits for tap sent by devicelab task
debugPrint('Continuing...');
// Wait out any errant taps due to synchronization
await Future<void>.delayed(const Duration(milliseconds: 200));
// remove onTap handler, enable pointer events for app
runApp(GestureDetector(child: const IgnorePointer(ignoring: false, child: ComplexLayoutApp())));
await SchedulerBinding.instance.endOfFrame;
final WidgetController controller = LiveWidgetController(WidgetsBinding.instance);
// Scroll down
for (int 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) {
debugPrint('Scroll up... $iteration/$maxIterations');
await controller.fling(find.byType(ListView), const Offset(0.0, 300.0), speed);
await Future<void>.delayed(pauses);
}
debugPrint('==== MEMORY BENCHMARK ==== DONE ====');
}