您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

159 行
5.0 KiB

using System;
using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Material = Unity.UIWidgets.material.Material;
using Text = Unity.UIWidgets.widgets.Text;
using ui_ = Unity.UIWidgets.widgets.ui_;
namespace UIWidgetsSample
{
public class AnimationDemo : UIWidgetsPanel
{
protected void OnEnable()
{
base.OnEnable();
}
protected override void main()
{
ui_.runApp(new HeroAnimation());
}
}
public class PhotoHero : StatelessWidget
{
public PhotoHero(Key key = null, string photo = null, GestureTapCallback onTap = null, float? width = null) :
base(key: key)
{
this.photo = photo;
this.onTap = onTap;
this.width = width;
}
string photo;
GestureTapCallback onTap;
float? width;
public override Widget build(BuildContext context)
{
return new Hero(
tag: photo,
child: new Material(
color: Colors.transparent,
child: new InkWell(
onTap: onTap,
child: new Lottie(photo, frame: 0, size: new Size(width.Value, width.Value))
)
)
);
}
}
class HeroAnimation : StatelessWidget
{
public override Widget build(BuildContext context)
{
return new MaterialApp(home: new Scaffold(
appBar: new AppBar(
title: new Text("Basic Hero Animation")
),
body: new Center(
child: new Builder(
builder: (context1) => new Column(children: new List<Widget>()
{
new Text("here is a hero animation"),
new PhotoHero(
photo: "66992-the-flying-rocket.json",
width: 200.0f,
onTap: () =>
{
Navigator.of(context1).push(new MaterialPageRoute(
builder: (BuildContext innerContext) => new MyHomePage()
));
}
)
}
)
)
)
)
);
}
}
public class MyHomePage : StatefulWidget
{
public override State createState() => new _MyHomePageState();
}
public class _MyHomePageState : SingleTickerProviderStateMixin<MyHomePage>
{
//*-----defining animation and animation controller-----*
AnimationController _controller;
Animation<Size> _myAnimation;
public override void initState()
{
base.initState();
_controller = new AnimationController(
vsync: this,
duration: TimeSpan.FromMilliseconds(1000)
);
_myAnimation = new SizeTween(
begin: new Size(100, 100),
end: new Size(120, 120)
).animate(
new CurvedAnimation(parent: _controller, curve: Curves.bounceIn)
);
_controller.addStatusListener((AnimationStatus status) =>
{
if (status == AnimationStatus.completed)
{
_controller.repeat();
}
});
}
public override void dispose()
{
base.dispose();
//-disposing the animation controller-
_controller.dispose();
}
public override Widget build(BuildContext context)
{
return new Scaffold(
appBar: new AppBar(
title: new Text("Flutter Animations")
),
body: new Center(
child:
new AnimatedBuilder(
animation: _myAnimation,
builder: (_, _controller) =>
new PhotoHero(
photo: "66992-the-flying-rocket.json",
width: _myAnimation.value.width
)
)
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.play_arrow),
onPressed: () => { _controller.forward(); }
)
);
}
}
}