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>
super.initState();
controller = AnimationController(
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)
..addListener(() {
setState(() {});
......
......@@ -18,6 +18,10 @@ class _CullOpacityPageState extends State<CullOpacityPage> with SingleTickerProv
super.initState();
_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((){
setState(() {});
});
......
......@@ -5,11 +5,11 @@
import 'package:flutter/material.dart';
class MultiWidgetConstructTable extends StatefulWidget {
const MultiWidgetConstructTable(this.column, this.row, {Key key})
const MultiWidgetConstructTable(this.columnCount, this.rowCount, {Key key})
: super(key: key);
final int column;
final int row;
final int columnCount;
final int rowCount;
@override
_MultiWidgetConstructTableState createState() =>
......@@ -24,60 +24,52 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
Colors.cyan, Colors.lightBlue, Colors.blue, Colors.indigo, Colors.purple,
];
int counter = 0;
Color baseColor = colorList[0][900];
AnimationController controller;
CurvedAnimation curve;
AnimationController _controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this, duration: const Duration(milliseconds: 10000));
curve = CurvedAnimation(parent: controller, curve: Curves.linear)
..addListener(() {
final double colorPosition = curve.value;
final int c1Position = (colorPosition * (colorList.length + 1)).floor();
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();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 10000),
lowerBound: 0,
upperBound: colorList.length + 1.0,
)..repeat();
}
@override
void dispose() {
controller.dispose();
_controller.dispose();
super.dispose();
}
@override
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 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++;
return Scaffold(
body: Table(
children: List<TableRow>.generate(
widget.row,
widget.rowCount,
(int row) => TableRow(
children: List<Widget>.generate(
widget.column,
widget.columnCount,
(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
? Container(
// This key forces rebuilding the element
......@@ -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