Created
April 20, 2021 07:54
-
-
Save maheshmnj/0313eb247c2f88a7556e605bf0ef3de6 to your computer and use it in GitHub Desktop.
rotate a box by x deg every 2 secs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file | |
// for details. All rights reserved. Use of this source code is governed by a | |
// BSD-style license that can be found in the LICENSE file. | |
import 'package:flutter/material.dart'; | |
import 'dart:math' as math; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: MainPage(), | |
); | |
} | |
} | |
class MainPage extends StatefulWidget { | |
@override | |
_MainPageState createState() => _MainPageState(); | |
} | |
class _MainPageState extends State<MainPage> | |
with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = | |
AnimationController(vsync: this, duration: Duration(seconds: 1)) | |
..addStatusListener((status) { | |
Future.delayed(Duration(seconds: 1), () { | |
if (status == AnimationStatus.completed) { | |
_controller.reset(); | |
_controller.forward(); | |
} | |
}); | |
}); | |
_controller.forward(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(), | |
body: Center( | |
child: AnimatedBuilder( | |
animation: _controller, | |
builder: (_, child) { | |
return Transform.rotate( | |
angle: _controller.value * (math.pi / 8), | |
child: child, | |
); | |
}, | |
child: Container(height: 200, width: 200, color: Colors.orangeAccent), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment