-
-
Save MarcinusX/ea49c86fee30f6aa85a73b4e22ff7c59 to your computer and use it in GitHub Desktop.
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
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