flutter - Flare Flutter 动画
问题描述
使用 Flare Flutter(来自 2dimensions.com)创建的动画不能在同一个 Flare Actor 的不同动画之间切换。如果先有黑色版本,则不会显示白色版本;如果首先是白色版本,则会显示黑色。
我不确定我是否做错了什么或者它是否是一个错误。它可以在颜色之间切换,但不能在动画之间切换。
import 'package:flutter/material.dart';
import 'package:flare_flutter/flare_actor.dart';
const List<String> animations = ['White', 'Black'];
const List<Color> colors = [Colors.blue, Colors.black];
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Animation Tester',
debugShowCheckedModeBanner: false,
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Animation Tester'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int index = 0;
void switchAnimation() {
setState(() {
index = index < (animations.length - 1) ? index + 1 : 0;
});
}
@override
Widget build(BuildContext context) {
print(index);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ListView(
children: <Widget>[
GestureDetector(
onTap: switchAnimation,
child: Icon(
Icons.add,
size: 100.0,
)),
Container(
width: 200.0,
height: 200.0,
child: FlareActor(
'assets/color_wheel_loading.flr',
color: colors[index],
)),
Container(
width: 200.0,
height: 200.0,
child: FlareActor(
'assets/color_wheel_loading.flr',
animation: animations[index],
)),
Center(child: Text('$index'))
],
)),
);
}
}
解决方案
我已经用我自己的文件测试了你的代码,它运行良好。可能是您的动画名称不对,您可以检查一下。
或者您可以使用下面的代码测试这个文件“ https://www.2dimensions.com/a/whitewolfnegizzz/files/flare/pj ”。
导入“包:颤振/material.dart”;导入“包:flare_flutter/flare_actor.dart”;
const List<String> animations = ['Build and Fade Out', 'Build'];
const List<Color> colors = [Colors.blue, Colors.black];
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Animation Tester',
debugShowCheckedModeBanner: false,
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Animation Tester'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int index = 0;
void switchAnimation() {
setState(() {
index = index < (animations.length - 1) ? index + 1 : 0;
});
}
@override
Widget build(BuildContext context) {
print(index);
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ListView(
children: <Widget>[
GestureDetector(
onTap: switchAnimation,
child: Icon(
Icons.add,
size: 100.0,
)),
Container(
width: 200.0,
height: 200.0,
child: FlareActor(
'assets/color_wheel_loading.flr',
color: colors[index],
)),
Container(
width: 200.0,
height: 200.0,
child: FlareActor(
'assets/Pj.flr',
animation: animations[index],
)),
Center(child: Text('$index'))
],
)),
);
}
}
推荐阅读
- php - 如何在aws弹性豆茎上放置ssl
- arrays - 循环通过数组并以角度显示数据
- function - 如何检查 Haskell 项目中参数是否过多或过少的函数调用
- reactjs - 如何添加 cookie 以便加载程序每天只显示一次
- python - 有多少人在一周中的每一天的给定时间工作,python
- angularjs - 需要根据折线图 D3.js 中的条件(或 Y 轴上的 0 位置)仅突出显示 DataGrid 中的一个刻度
- javascript - 传入路由的 React Shell 组件支持组件
- regex - 在 perl 或 sed 中默认不匹配的反向引用
- python - 有没有办法将数据读入 R 或 Python 并按字符数拆分?
- r - Github Actions - R 包 R-CMD-Check “找不到 PhantomJS”