Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 1 | // 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 | |
| 5 | import 'package:flutter/widgets.dart'; |
| 6 | |
Adam Barth | 95fc5ae | 2016-03-12 12:13:16 -0800 | [diff] [blame] | 7 | class SpinningSquare extends StatefulWidget { |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 8 | @override |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 9 | _SpinningSquareState createState() => _SpinningSquareState(); |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 10 | } |
| 11 | |
Ian Hickson | 9e67385 | 2016-09-26 10:57:10 -0700 | [diff] [blame] | 12 | class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProviderStateMixin { |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 13 | AnimationController _animation; |
| 14 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 15 | @override |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 16 | 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 Simmons | 466d154 | 2018-03-12 11:06:32 -0700 | [diff] [blame] | 20 | // we used 0.0 -> math.pi, which is only half a turn. |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 21 | _animation = AnimationController( |
Ian Hickson | 9e67385 | 2016-09-26 10:57:10 -0700 | [diff] [blame] | 22 | duration: const Duration(milliseconds: 3600), |
| 23 | vsync: this, |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 24 | )..repeat(); |
| 25 | } |
| 26 | |
Hixie | 797e27e | 2016-03-14 13:31:43 -0700 | [diff] [blame] | 27 | @override |
Adam Barth | 22210c8 | 2016-08-04 08:55:59 -0700 | [diff] [blame] | 28 | void dispose() { |
| 29 | _animation.dispose(); |
| 30 | super.dispose(); |
| 31 | } |
| 32 | |
| 33 | @override |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 34 | Widget build(BuildContext context) { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 35 | return RotationTransition( |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 36 | turns: _animation, |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 37 | child: Container( |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 38 | width: 200.0, |
| 39 | height: 200.0, |
Ian Hickson | 36052e6 | 2017-04-27 14:19:01 -0700 | [diff] [blame] | 40 | color: const Color(0xFF00FF00), |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 41 | ) |
| 42 | ); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void main() { |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame] | 47 | runApp(Center(child: SpinningSquare())); |
Adam Barth | 948ae15 | 2016-02-13 00:52:56 -0800 | [diff] [blame] | 48 | } |