Skip to content

Instantly share code, notes, and snippets.

@alexmercerind
Created June 22, 2020 11:50
Show Gist options
  • Save alexmercerind/3b47e268449d1bae277fd2f1b572267e to your computer and use it in GitHub Desktop.
Save alexmercerind/3b47e268449d1bae277fd2f1b572267e to your computer and use it in GitHub Desktop.
Flutter Explicit Animations using AnimatedController
import 'package:flutter/material.dart';
import 'dart:math';
void main() {
runApp(new Application());
}
class AnimationControllerWidget extends StatefulWidget {
final String text;
AnimationControllerWidget({this.text});
_AnimationControllerWidgetState createState() => _AnimationControllerWidgetState();
}
class _AnimationControllerWidgetState extends State<AnimationControllerWidget>
with SingleTickerProviderStateMixin {
AnimationController _controller;
@override initState() {
super.initState();
_controller = AnimationController(
vsync: this,
lowerBound: 0,
upperBound: 1,
reverseDuration: Duration(milliseconds: 2000),
duration: Duration(milliseconds: 2000),
)..repeat();
}
@override
Widget build(BuildContext context) {
return ScaleTransition(
alignment: Alignment.center,
child: Icon(Icons.album, size: 192),
scale: _controller,
);
}
}
/*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",)
AnimationControllerWidget(text: "Hello World!")
],)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment