Last active
April 8, 2021 13:57
-
-
Save guid-empty/fa59b40763ca29fe3d8ca854c943bc69 to your computer and use it in GitHub Desktop.
Explicit Animations - RotationTransition
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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: MyHomePage(), | |
); | |
} | |
} | |
const double _logoSize = 200.0; | |
class OtusLogo extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Image.network('https://github.com/flutter-cats/otus-cocktails-application/blob/master/logo-2.8602b.svg'), | |
width: _logoSize, | |
height: _logoSize, | |
color: Colors.green, | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> | |
with SingleTickerProviderStateMixin { | |
AnimationController _controller; | |
@override | |
void initState() { | |
super.initState(); | |
_controller = AnimationController( | |
vsync: this, | |
duration: const Duration(seconds: 1), | |
); | |
} | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Explicit Animations - RotationTransition'), | |
), | |
body: Center( | |
child: Container( | |
height: 300, | |
child: Stack( | |
children: <Widget>[ | |
RotationTransition( | |
turns: _controller, | |
child: OtusLogo(), | |
), | |
], | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
if (_controller.isAnimating) { | |
_controller.stop(); | |
} else { | |
_controller.repeat(); | |
} | |
setState(() {}); | |
}, | |
child: | |
_controller.isAnimating ? Icon(Icons.stop) : Icon(Icons.play_arrow), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment