Last active
November 5, 2020 15:19
-
-
Save guid-empty/6007bd2a3f838ebe242659a69326123c to your computer and use it in GitHub Desktop.
Explicit Animations - Animation controller - scenario
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(), | |
); | |
} | |
} | |
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, | |
lowerBound: 0, // default value | |
upperBound: 1000, // default value | |
duration: const Duration(seconds: 1), | |
); | |
_controller.addListener(() { | |
print(_controller.value.toStringAsFixed(4)); | |
setState(() {}); | |
}); | |
_controller.addStatusListener((status) { | |
print(_controller.status); | |
}); | |
} | |
void dispose() { | |
_controller.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Explicit Animations - Animation controller - scenario'), | |
), | |
body: Center( | |
child: Container( | |
height: 300, | |
child: Column( | |
children: [ | |
Text('${_controller.value.toStringAsFixed(4)} -> Check console output'), | |
Text('${_controller.status} -> Check console output'), | |
], | |
)), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
_controller | |
..reset() | |
..forward(); | |
}, | |
child: Icon(Icons.play_arrow), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment