Unverified Commit 29306b08 authored by Harry Terkelsen's avatar Harry Terkelsen Committed by GitHub

[Web] Add Material Card Infinite Scroll benchmark (#51005)

* [Web] Add Material Card Infinite Scroll benchmark

Adds a benchmark that makes an infinite list of Material cards
and scrolls it. This benchmark exercises more heavyweight rendering
like shadows and clipping and paths.

* Fix analyzer warnings. Respond to comments
parent 52ee8a6c
// 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:flutter/material.dart';
import 'recorder.dart';
import 'test_data.dart';
/// Creates an infinite list of Material cards and scrolls it.
class BenchCardInfiniteScroll extends WidgetRecorder {
BenchCardInfiniteScroll() : super(name: benchmarkName);
static const String benchmarkName = 'bench_card_infinite_scroll';
@override
Widget createWidget() => const MaterialApp(
title: 'Infinite Card Scroll Benchmark',
home: _InfiniteScrollCards(),
);
}
class _InfiniteScrollCards extends StatefulWidget {
const _InfiniteScrollCards({Key key}) : super(key: key);
@override
State<_InfiniteScrollCards> createState() => _InfiniteScrollCardsState();
}
class _InfiniteScrollCardsState extends State<_InfiniteScrollCards> {
ScrollController scrollController;
double offset;
static const double distance = 1000;
static const Duration stepDuration = Duration(seconds: 1);
@override
void initState() {
super.initState();
scrollController = ScrollController();
offset = 0;
// Without the timer the animation doesn't begin.
Timer.run(() async {
while (true) {
await scrollController.animateTo(
offset + distance,
curve: Curves.linear,
duration: stepDuration,
);
offset += distance;
}
});
}
@override
Widget build(BuildContext context) {
return ListView.builder(
controller: scrollController,
itemBuilder: (BuildContext context, int index) {
return SizedBox(
height: 100.0,
child: Card(
elevation: 16.0,
child: Text(
lipsum[index % lipsum.length],
textAlign: TextAlign.center,
),
),
);
},
);
}
}
......@@ -8,6 +8,7 @@ import 'dart:html' as html;
import 'package:macrobenchmarks/src/web/bench_text_out_of_picture_bounds.dart';
import 'src/web/bench_card_infinite_scroll.dart';
import 'src/web/bench_draw_rect.dart';
import 'src/web/bench_simple_lazy_text_scroll.dart';
import 'src/web/bench_text_out_of_picture_bounds.dart';
......@@ -16,6 +17,7 @@ import 'src/web/recorder.dart';
typedef RecorderFactory = Recorder Function();
final Map<String, RecorderFactory> benchmarks = <String, RecorderFactory>{
BenchCardInfiniteScroll.benchmarkName: () => BenchCardInfiniteScroll(),
BenchDrawRect.benchmarkName: () => BenchDrawRect(),
BenchTextOutOfPictureBounds.benchmarkName: () => BenchTextOutOfPictureBounds(),
BenchSimpleLazyTextScroll.benchmarkName: () => BenchSimpleLazyTextScroll(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment