Last active
December 10, 2019 20:37
-
-
Save mingsai/4fe39fc565a5e81f78a9685f6420698c to your computer and use it in GitHub Desktop.
Single/Multiple Animation Builder
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
SingleAnimationBuilder _timeAnimation(int number) { | |
final duration = Duration(milliseconds: 500); | |
return SingleAnimationBuilder( | |
duration: duration, | |
buildInfo: SingleAnimationBuildInfo( | |
animatable: Tween<double>(begin: 25, end: 100), | |
from: Duration.zero, | |
duration: duration), | |
buildAnimation: (context, data) { | |
return Text( | |
'$number', | |
style: TextStyle(fontSize: data.value), | |
); | |
}, | |
); | |
} | |
MultipleAnimationBuilder _multipleAnimation() { | |
final duration = Duration(seconds: 10); | |
final builder = MultipleAnimationBuilder( | |
duration: duration, | |
buildAnimation: (context, map) { | |
final Color color = map['color'].value; | |
final complementaryColor = Color(0xffffff ^ color.value); | |
return ClipRRect( | |
borderRadius: | |
BorderRadius.all(Radius.circular(map['radius'].value)), | |
child: Container( | |
height: map['height'].value, | |
width: map['width'].value, | |
color: color, | |
child: Center( | |
child: Text( | |
'${map['color'].value}', | |
style: TextStyle(color: complementaryColor), | |
), | |
), | |
), | |
); | |
}); | |
builder | |
.addAnimatable( | |
animatable: Tween<double>(begin: 100, end: 400), | |
from: Duration(seconds: 1), | |
duration: Duration(seconds: 4), | |
key: 'height') | |
.addAnimatable( | |
animatable: Tween<double>(begin: 400, end: 100), | |
from: Duration.zero, | |
duration: Duration(seconds: 4), | |
key: 'width') | |
.addAnimatable( | |
animatable: | |
ColorTween(begin: Colors.green, end: Colors.yellowAccent), | |
from: Duration(seconds: 2), | |
duration: Duration(seconds: 4), | |
key: 'color') | |
.addAnimatable( | |
animatable: Tween<double>(begin: 400, end: 100), | |
from: Duration(seconds: 5), | |
duration: Duration(seconds: 5), | |
key: 'height') | |
.addAnimatable( | |
animatable: Tween<double>(begin: 100, end: 400), | |
from: Duration(seconds: 5), | |
duration: Duration(seconds: 5), | |
key: 'width') | |
.addAnimatable( | |
animatable: ColorTween(begin: Colors.yellowAccent, end: Colors.red), | |
from: Duration(seconds: 4), | |
duration: Duration(seconds: 3), | |
key: 'color') | |
.addAnimatable( | |
animatable: ColorTween(begin: Colors.red, end: Colors.black), | |
from: Duration(seconds: 7), | |
duration: Duration(seconds: 3), | |
key: 'color') | |
.addAnimatable( | |
animatable: Tween<double>(begin: 0, end: 200), | |
from: Duration(seconds: 3), | |
duration: Duration(seconds: 2), | |
key: 'radius') | |
.addAnimatable( | |
animatable: Tween<double>(begin: 200, end: 0), | |
from: Duration(seconds: 5), | |
duration: Duration(seconds: 5), | |
key: 'radius'); | |
return builder; | |
} | |
NoneAnimationBuilder _waitStep(int second) { | |
return NoneAnimationBuilder( | |
duration: Duration(seconds: second), | |
builder: (context) { | |
return Container( | |
color: Colors.black, | |
height: 100, | |
width: 400, | |
child: Center( | |
child: Text( | |
'just wait ${second}s', | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
); | |
}); | |
} | |
SingleAnimationBuilder _moreStepsAnimation() { | |
return SingleAnimationBuilder( | |
duration: Duration(seconds: 10), | |
buildAnimation: (context, animation) { | |
return Container( | |
color: Colors.black, | |
height: animation.value, | |
width: 400, | |
child: Center( | |
child: Text( | |
'more steps', | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
); | |
}, | |
buildInfo: SingleAnimationBuildInfo( | |
animatable: Tween<double>(begin: 100, end: 1000), | |
from: Duration.zero, | |
duration: Duration(seconds: 8), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment