Created
June 22, 2020 10:56
-
-
Save alexmercerind/3c4e911ff83c308144b880ce97facbd8 to your computer and use it in GitHub Desktop.
Flutter TweenAnimationBuilder
This file contains hidden or 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'; | |
import 'dart:math'; | |
void main() { | |
runApp(new Application()); | |
} | |
class TweenAnimation extends StatefulWidget { | |
final String message; | |
TweenAnimation({this.message}); | |
_TweenAnimationState createState() => _TweenAnimationState(); | |
} | |
class _TweenAnimationState extends State<TweenAnimation> { | |
double _rotationValue = 0; | |
@override | |
Widget build(BuildContext context) { | |
return( | |
Column(children: [ | |
Center(child: TweenAnimationBuilder( | |
duration: Duration(milliseconds: 200), | |
tween: Tween<double>(begin: 0, end: _rotationValue), | |
builder: (_, double angle, __) { | |
return Transform.rotate(angle: angle, | |
child: Text("Hello I'm a ${widget.message} !", style: TextStyle(fontSize: 16)) | |
); | |
}, | |
),), | |
Slider(min: 0, max: 2*pi, onChanged: (value) => setState(() {_rotationValue = value;}), value: _rotationValue) | |
]) | |
); | |
} | |
} | |
/*class Counter extends StatefulWidget { | |
final String name; | |
Counter(this.name); | |
_CounterState createState() => _CounterState(); | |
} | |
class _CounterState extends State<Counter> { | |
int _counterValue = 0; | |
bool _scaleValue = false; | |
void incrementCounter() { | |
setState(() {_counterValue++; this._scaleValue =! this._scaleValue;}); | |
//print('(' + MediaQuery.of(context).size.width.toString() + ', ' + MediaQuery.of(context).size.height.toString() + ')'); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return( | |
AnimatedContainer( | |
height: this._scaleValue ? 200 : 100, | |
padding: EdgeInsets.all(10), | |
margin: EdgeInsets.all(10), | |
curve: Curves.easeOutCubic, | |
duration: Duration(milliseconds: 200), | |
alignment: Alignment.center, | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.center, | |
mainAxisSize: MainAxisSize.max, | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: <Widget>[ | |
Text('${widget.name} : $_counterValue', style: TextStyle(fontSize: 16)), | |
RaisedButton(child: Text("ADD", style: TextStyle(color: Colors.white)), onPressed: incrementCounter, color: Colors.blue) | |
], | |
), | |
) | |
); | |
} | |
}*/ | |
class Application extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "Hello World!", | |
theme: ThemeData(primarySwatch: Colors.blue), | |
home: Scaffold( | |
appBar: AppBar(title: Text("Hello World!")), | |
body: Column(children: [ | |
//Counter("The current counter value"), | |
TweenAnimation(message: "Rotating Text",) | |
],) | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment