Unverified Commit 59aed976 authored by Ming Lyu (CareF)'s avatar Ming Lyu (CareF) Committed by GitHub

Simplify the animation control for macrobenchmarks test case (#60412)

* Simplify the animation control

* Using AnimatedBuilder
parent 839dc27e
...@@ -312,6 +312,10 @@ class AnimatedBezierState extends State<AnimatedBezier> ...@@ -312,6 +312,10 @@ class AnimatedBezierState extends State<AnimatedBezier>
super.initState(); super.initState();
controller = AnimationController( controller = AnimationController(
vsync: this, duration: const Duration(milliseconds: 1000)); vsync: this, duration: const Duration(milliseconds: 1000));
// Animations are typically implemented using the AnimatedBuilder widget.
// This code uses a manual listener for historical reasons and will remain
// in order to preserve compatibility with the history of measurements for
// this benchmark.
curve = CurvedAnimation(parent: controller, curve: Curves.linear) curve = CurvedAnimation(parent: controller, curve: Curves.linear)
..addListener(() { ..addListener(() {
setState(() {}); setState(() {});
......
...@@ -18,6 +18,10 @@ class _CullOpacityPageState extends State<CullOpacityPage> with SingleTickerProv ...@@ -18,6 +18,10 @@ class _CullOpacityPageState extends State<CullOpacityPage> with SingleTickerProv
super.initState(); super.initState();
_controller = AnimationController(vsync: this, duration: const Duration(seconds: 2)); _controller = AnimationController(vsync: this, duration: const Duration(seconds: 2));
// Animations are typically implemented using the AnimatedBuilder widget.
// This code uses a manual listener for historical reasons and will remain
// in order to preserve compatibility with the history of measurements for
// this benchmark.
_offsetY = Tween<double>(begin: 0, end: -1000.0).animate(_controller)..addListener((){ _offsetY = Tween<double>(begin: 0, end: -1000.0).animate(_controller)..addListener((){
setState(() {}); setState(() {});
}); });
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class MultiWidgetConstructTable extends StatefulWidget { class MultiWidgetConstructTable extends StatefulWidget {
const MultiWidgetConstructTable(this.column, this.row, {Key key}) const MultiWidgetConstructTable(this.columnCount, this.rowCount, {Key key})
: super(key: key); : super(key: key);
final int column; final int columnCount;
final int row; final int rowCount;
@override @override
_MultiWidgetConstructTableState createState() => _MultiWidgetConstructTableState createState() =>
...@@ -24,60 +24,52 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable> ...@@ -24,60 +24,52 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
Colors.cyan, Colors.lightBlue, Colors.blue, Colors.indigo, Colors.purple, Colors.cyan, Colors.lightBlue, Colors.blue, Colors.indigo, Colors.purple,
]; ];
int counter = 0; int counter = 0;
Color baseColor = colorList[0][900];
AnimationController controller; AnimationController _controller;
CurvedAnimation curve;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
controller = AnimationController( _controller = AnimationController(
vsync: this, duration: const Duration(milliseconds: 10000)); vsync: this,
curve = CurvedAnimation(parent: controller, curve: Curves.linear) duration: const Duration(milliseconds: 10000),
..addListener(() { lowerBound: 0,
final double colorPosition = curve.value; upperBound: colorList.length + 1.0,
final int c1Position = (colorPosition * (colorList.length + 1)).floor(); )..repeat();
final Color c1 = colorList[c1Position % colorList.length][900];
final Color c2 = colorList[(c1Position + 1) % colorList.length][900];
setState(() {
baseColor = Color.lerp(
c1, c2, colorPosition * (colorList.length + 1) - c1Position);
});
})
..addStatusListener((AnimationStatus state) {
if (state == AnimationStatus.completed) {
controller.reverse();
} else if (state == AnimationStatus.dismissed) {
controller.reset();
controller.forward();
}
});
controller.forward();
} }
@override @override
void dispose() { void dispose() {
controller.dispose(); _controller.dispose();
super.dispose(); super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final int totalLength = widget.row * widget.column; return AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, _) {
final int totalLength = widget.rowCount * widget.columnCount;
final int widgetCounter = counter * totalLength; final int widgetCounter = counter * totalLength;
final double height = MediaQuery.of(context).size.height / widget.column; final double height = MediaQuery.of(context).size.height / widget.rowCount;
final double colorPosition = _controller.value;
final int c1Position = colorPosition.floor();
final Color c1 = colorList[c1Position % colorList.length][900];
final Color c2 = colorList[(c1Position + 1) % colorList.length][900];
final Color baseColor = Color.lerp(c1, c2, colorPosition - c1Position);
counter++; counter++;
return Scaffold( return Scaffold(
body: Table( body: Table(
children: List<TableRow>.generate( children: List<TableRow>.generate(
widget.row, widget.rowCount,
(int row) => TableRow( (int row) => TableRow(
children: List<Widget>.generate( children: List<Widget>.generate(
widget.column, widget.columnCount,
(int column) { (int column) {
final int label = row * widget.column + column; final int label = row * widget.columnCount + column;
// This implementation rebuild the widget tree for every
// frame, and is intentionally designed of poor performance
// for benchmark purposes.
return counter % 2 == 0 return counter % 2 == 0
? Container( ? Container(
// This key forces rebuilding the element // This key forces rebuilding the element
...@@ -101,6 +93,8 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable> ...@@ -101,6 +93,8 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
), ),
), ),
); );
},
);
} }
} }
......
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