您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
68 行
1.9 KiB
68 行
1.9 KiB
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<AnimateButton>
|
|
{
|
|
private AnimationController selectAnim;
|
|
private Animation<Color> _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);
|
|
}
|
|
);
|
|
}
|
|
}
|
|
}
|