• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5import 'package:flutter/widgets.dart';
6
7class SpinningSquare extends StatefulWidget {
8  @override
9  _SpinningSquareState createState() => _SpinningSquareState();
10}
11
12class _SpinningSquareState extends State<SpinningSquare> with SingleTickerProviderStateMixin {
13  AnimationController _animation;
14
15  @override
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
20    // we used 0.0 -> math.pi, which is only half a turn.
21    _animation = AnimationController(
22      duration: const Duration(milliseconds: 3600),
23      vsync: this,
24    )..repeat();
25  }
26
27  @override
28  void dispose() {
29    _animation.dispose();
30    super.dispose();
31  }
32
33  @override
34  Widget build(BuildContext context) {
35    return RotationTransition(
36      turns: _animation,
37      child: Container(
38        width: 200.0,
39        height: 200.0,
40        color: const Color(0xFF00FF00),
41      ),
42    );
43  }
44}
45
46void main() {
47  runApp(Center(child: SpinningSquare()));
48}
49