import ‘package:flutter/material.dart’;
// 旋转小人儿
class RotateGirlMainPage extends StatefulWidget {
@override
_RotateGirlMainPageState createState() => _RotateGirlMainPageState();
}
class _RotateGirlMainPageState extends State
with SingleTickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
super.initState();
_controller = new AnimationController(
vsync: this, duration: const Duration(milliseconds: 1500));
_controller.repeat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(“旋转小人儿”),
centerTitle: true,
),
body: CustomPaint(
size: MediaQuery.of(context).size,
painter: _MyPainter(_controller),
),
);
}
}
class _MyPainter extends CustomPainter {
AnimationController _controller;
_MyPainter(this._controller) : super(repaint: _controller);
@override
void paint(Canvas canvas, Size size) {
translateToCenter(canvas, size);
double dy = 10 * sin(pi * 2 * _controller.value);
Path path = new Path()
…moveTo(30 * sin(pi *