using System; using uiwidgets; using Unity.UIWidgets.animation; using Unity.UIWidgets.foundation; using Unity.UIWidgets.painting; using Unity.UIWidgets.service; using Unity.UIWidgets.ui; using Unity.UIWidgets.widgets; using UnityEngine; namespace Unity.UIWidgets.material { public class ExpandIcon : StatefulWidget { public ExpandIcon( Key key = null, bool isExpanded = false, float size = 24.0f, ValueChanged onPressed = null, EdgeInsets padding = null) : base(key: key) { this.isExpanded = isExpanded; this.size = size; this.onPressed = onPressed; this.padding = padding ?? EdgeInsets.all(8.0f); } public readonly bool isExpanded; public readonly float size; public readonly ValueChanged onPressed; public readonly EdgeInsets padding; public override State createState() { return new _ExpandIconState(); } } public class _ExpandIconState : SingleTickerProviderStateMixin { AnimationController _controller; Animation _iconTurns; static readonly Animatable _iconTurnTween = new FloatTween(begin: 0.0f, end: 0.5f).chain(new CurveTween(curve: Curves.fastOutSlowIn)); public override void initState() { base.initState(); _controller = new AnimationController(duration: ThemeUtils.kThemeAnimationDuration, vsync: this); _iconTurns = _controller.drive(_iconTurnTween); if (widget.isExpanded) { _controller.setValue(Mathf.PI); } } public override void dispose() { _controller.dispose(); base.dispose(); } public override void didUpdateWidget(StatefulWidget oldWidget) { base.didUpdateWidget(oldWidget); ExpandIcon _oldWidget = (ExpandIcon) oldWidget; if (widget.isExpanded != _oldWidget.isExpanded) { if (widget.isExpanded) { _controller.forward(); } else { _controller.reverse(); } } } void _handlePressed() { if (widget.onPressed != null) { widget.onPressed(widget.isExpanded); } } public override Widget build(BuildContext context) { D.assert(material_.debugCheckHasMaterial(context)); ThemeData theme = Theme.of(context); return new IconButton( padding: widget.padding, color: theme.brightness == Brightness.dark ? Colors.white54 : Colors.black54, onPressed: widget.onPressed == null ? (VoidCallback) null : _handlePressed, icon: new RotationTransition( turns: _iconTurns, child: new Icon(Icons.expand_more)) ); } } }