using System; using uiwidgets; using Unity.UIWidgets.animation; using Unity.UIWidgets.foundation; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; namespace UIWidgetsSample.RaycastableScene { public class AnimateButton : StatefulWidget { public AnimateButton(Key key = null, Widget child = null, bool selected = false) : base(key: key) { this.child = child; this.selected = selected; } public readonly Widget child; public readonly bool selected; public override State createState() { return new AnimateButtonState(); } } public class AnimateButtonState : SingleTickerProviderStateMixin { private AnimationController selectAnim; private Animation _colorTween; public override void initState() { selectAnim = new AnimationController(vsync: this, duration: new TimeSpan(0, 0, 0, 0, 200)); _colorTween = new ColorTween(begin: Colors.white, Colors.green).animate(selectAnim); base.initState(); } public override void dispose() { base.dispose(); selectAnim.dispose(); } public override Widget build(BuildContext context) { if (widget.selected) { selectAnim.forward(); } else { selectAnim.reverse(); } return new AnimatedBuilder( animation: _colorTween, builder: (build_context, child) => { return new Container( color: _colorTween.value, child: widget.child); } ); } } }