


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】如何使用Flutter實現(xiàn)動畫效果
本篇文章為大家展示了如何使用Flutter實現(xiàn)動畫效果,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。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)
);
}
}要在我們的應(yīng)用程序中使用彩色條形,需要更新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];
//
返回集合中的元素數(shù)量
int
get
length
=>
_colors.length;
/*
int
nextInt(
int
max
)
生成一個非負隨機整數(shù),范圍從0到max(包括max)
*/
Color
random(Random
random)
=>
this[random.nextInt(length)];
}我們將把Bar.empty和Bar.random工廠構(gòu)造函數(shù)放在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中,我們需要創(chuàng)建一個空的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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年宏觀經(jīng)濟學(xué)課件:跨學(xué)科視角
- 2025年麗水貨運從業(yè)資格證模擬考試下載安裝
- 市場渠道管理效果統(tǒng)計表
- 2025年安徽郵電職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性考試題庫及參考答案1套
- 建筑設(shè)計理念與設(shè)計方法試題
- 餐廳狀態(tài)統(tǒng)計表
- 產(chǎn)品性能指標表-電子產(chǎn)品行業(yè)
- 2025年江西貨運從業(yè)資格考試題目及答案大全及解析
- 《牛頓第二定律的應(yīng)用:高中物理必修課程教案》
- 技術(shù)服務(wù)委托合同
- 2025年廣東生態(tài)工程職業(yè)學(xué)院單招職業(yè)適應(yīng)性測試題庫完美版
- 模具轉(zhuǎn)移合同協(xié)議書
- DeepSeek學(xué)習(xí)科普專題
- 2025浙江杭州地鐵運營分公司校園招聘665人易考易錯模擬試題(共500題)試卷后附參考答案
- 2025四川省小金縣事業(yè)單位招聘362人歷年高頻重點模擬試卷提升(共500題附帶答案詳解)
- 2022泛海三江消防ZX900液晶手動控制盤使用手冊
- 廣西壯族自治區(qū)柳州市2025年中考物理模擬考試卷三套附答案
- 第11課《山地回憶》說課稿 2024-2025學(xué)年統(tǒng)編版語文七年級下冊
- 羅森運營部經(jīng)營管理手冊
- 高標準農(nóng)田施工組織設(shè)計
- 老舊小區(qū)改造項目施工組織設(shè)計方案
評論
0/150
提交評論