Instantly share code, notes, and snippets.

Embed
What would you like to do?
class _GenderCardState extends State<GenderCard> with SingleTickerProviderStateMixin {
AnimationController _arrowAnimationController; //<--- Add controller
Gender selectedGender;
@override
void initState() {
selectedGender = widget.initialGender ?? Gender.other;
_arrowAnimationController = new AnimationController( //<--- initialize animation controller
vsync: this,
lowerBound: -_defaultGenderAngle,
upperBound: _defaultGenderAngle,
value: _genderAngles[selectedGender],
);
super.initState();
}
@override
void dispose() {
_arrowAnimationController.dispose(); //<--- dispose controller when we're done
super.dispose();
}
Widget _drawCircleIndicator() {
return Stack(
alignment: Alignment.center,
children: <Widget>[
GenderCircle(),
GenderArrow(listenable: _arrowAnimationController), //<--- Update constructor
],
);
}
_drawGestureDetector() {
return Positioned.fill(
child: TapHandler(
onGenderTapped: _setSelectedGender, //<--- Update tap handling
),
);
}
void _setSelectedGender(Gender gender) {
setState(() => selectedGender = gender);
_arrowAnimationController.animateTo( //<--- Animate the arrow
_genderAngles[gender],
duration: Duration(milliseconds: 150),
);
}
}
class GenderArrow extends AnimatedWidget { //<--- Use AnimatedWidget
const GenderArrow({Key key, Listenable listenable}) : super(key: key, listenable: listenable);
@override
Widget build(BuildContext context) {
Animation animation = listenable;
return Transform.rotate(
angle: animation.value, //<--- use animation value
...
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment