blob: 6539ffc3a4a1ec8d7d5bbb2d4cc00b0eea4e84e8 [file] [log] [blame]
Adam Barth948ae152016-02-13 00:52:56 -08001// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'package:flutter/widgets.dart';
6
Adam Barth95fc5ae2016-03-12 12:13:16 -08007class SpinningSquare extends StatefulWidget {
Hixie797e27e2016-03-14 13:31:43 -07008 @override
Alexandre Ardhuind927c932018-09-12 08:29:29 +02009 _SpinningSquareState createState() => _SpinningSquareState();
Adam Barth948ae152016-02-13 00:52:56 -080010}
11
Ian Hickson9e673852016-09-26 10:57:10 -070012class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProviderStateMixin {
Adam Barth948ae152016-02-13 00:52:56 -080013 AnimationController _animation;
14
Hixie797e27e2016-03-14 13:31:43 -070015 @override
Adam Barth948ae152016-02-13 00:52:56 -080016 void initState() {
17 super.initState();
18 // We use 3600 milliseconds instead of 1800 milliseconds because 0.0 -> 1.0
19 // represents an entire turn of the square whereas in the other examples
Jason Simmons466d1542018-03-12 11:06:32 -070020 // we used 0.0 -> math.pi, which is only half a turn.
Alexandre Ardhuind927c932018-09-12 08:29:29 +020021 _animation = AnimationController(
Ian Hickson9e673852016-09-26 10:57:10 -070022 duration: const Duration(milliseconds: 3600),
23 vsync: this,
Adam Barth948ae152016-02-13 00:52:56 -080024 )..repeat();
25 }
26
Hixie797e27e2016-03-14 13:31:43 -070027 @override
Adam Barth22210c82016-08-04 08:55:59 -070028 void dispose() {
29 _animation.dispose();
30 super.dispose();
31 }
32
33 @override
Adam Barth948ae152016-02-13 00:52:56 -080034 Widget build(BuildContext context) {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020035 return RotationTransition(
Adam Barth948ae152016-02-13 00:52:56 -080036 turns: _animation,
Alexandre Ardhuind927c932018-09-12 08:29:29 +020037 child: Container(
Adam Barth948ae152016-02-13 00:52:56 -080038 width: 200.0,
39 height: 200.0,
Ian Hickson36052e62017-04-27 14:19:01 -070040 color: const Color(0xFF00FF00),
Adam Barth948ae152016-02-13 00:52:56 -080041 )
42 );
43 }
44}
45
46void main() {
Alexandre Ardhuind927c932018-09-12 08:29:29 +020047 runApp(Center(child: SpinningSquare()));
Adam Barth948ae152016-02-13 00:52:56 -080048}