付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】如何使用Flutter实现动画效果
本篇文章为大家展示了如何使用Flutter实现动画效果,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。class
Bar
{
Bar(this.height,
this.color);
final
double
height;
final
Color
color;
static
Bar
lerp(Bar
begin,
Bar
end,
double
t)
{
return
new
Bar(
lerpDouble(begin.height,
end.height,
t),
Color.lerp(begin.color,
end.color,
t)
);
}
}要在我们的应用程序中使用彩色条形,需要更新BarChartPainter以从Bar获取条形颜色。class
BarChartPainter
extends
CustomPainter
{
//
...
@override
void
paint(Canvas
canvas,
Size
size)
{
final
bar
=
animation.value;
final
paint
=
new
Paint()
//
从Bar获取条形颜色
..color
=
bar.color
..style
=
PaintingStyle.fill;
//
...
//
...
}在main.dart同级目录下新建color_palette.dart文件,用于获取颜色。import
'package:flutter/material.dart';
import
'dart:math';
class
ColorPalette
{
static
final
ColorPalette
primary
=
new
ColorPalette(<Color>[
Colors.blue[400],
Colors.red[400],
Colors.green[400],
Colors.yellow[400],
Colors.purple[400],
Colors.orange[400],
Colors.teal[400],
]);
ColorPalette(List<Color>
colors)
:
_colors
=
colors
{
//
bool
isNotEmpty:如果此集合中至少有一个元素,则返回true
assert(colors.isNotEmpty);
}
final
List<Color>
_colors;
Color
operator
[](int
index)
=>
_colors[index
%
length];
//
返回集合中的元素数量
int
get
length
=>
_colors.length;
/*
int
nextInt(
int
max
)
生成一个非负随机整数,范围从0到max(包括max)
*/
Color
random(Random
random)
=>
this[random.nextInt(length)];
}我们将把Bar.empty和Bar.random工厂构造函数放在Bar上。class
Bar
{
Bar(this.height,
this.color);
final
double
height;
final
Color
color;
factory
Bar.empty()
=>
new
Bar(0.0,
Colors.transparent);
factory
Bar.random(Random
random)
{
return
new
Bar(
random.nextDouble()
*
100.0,
ColorPalette.primary.random(random)
);
}
static
Bar
lerp(Bar
begin,
Bar
end,
double
t)
{
return
new
Bar(
lerpDouble(begin.height,
end.height,
t),
Color.lerp(begin.color,
end.color,
t)
);
}
}在main.dart中,我们需要创建一个空的Bar和一个随机的Bar。我们将为前者使用完全透明的颜色,后者将使用随机颜色。class
_MyHomePageState
extends
State<MyHomePage>
with
TickerProviderStateMixin
{
//
...
@override
void
initState()
{
//
...
tween
=
new
BarTween(new
Bar.empty(),
new
Bar.random(random));
animation.forward();
}
//
...
void
changeData()
{
setState(()
{
tween
=
new
BarTween(
tween.ev
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 安全员A证考试综合提升试卷含答案详解【综合题】
- 2025年湖南省长沙中小学教师招聘考试真题解析含答案
- 企业信息化系统安全管理方案
- 安全员A证考试考试押题密卷ab卷附答案详解
- 幼儿园科学启蒙主题活动活动方案
- 项目式学习:基于碳中和理念的校园低碳行动方案设计与论证-九年级化学跨学科实践课
- 品牌推广策略及媒介传播方案生成工具
- 幼儿体测工作方案模板
- 养鸡建设布局方案
- 促进动物防疫工作方案
- 统编版九年级上册语文期末复习:全册重点考点手册
- 2025年11月15日江西省市直遴选笔试真题及解析(B卷)
- 小学生科普小知识:静电
- 重庆市康德2025届高三上学期第一次诊断检测-数学试卷(含答案)
- 导乐用具使用课件
- “师生机”协同育人模式的实践探索与效果评估
- 公路施工组织设计附表
- DBJT15-186-2020 高强混凝土强度回弹法检测技术规程
- 风电场库管理办法
- 金属楼梯维修方案(3篇)
- 春季学期期末教职工大会校长讲话:那些“看不见”的努力终将照亮教育的方向
评论
0/150
提交评论