android-studio - 如何在 Flutter 中处理 NimaAnimations
问题描述
我在我的一个 Dart 文件中使用了 Nima 瞄准。但是,一旦完成,我将无法处理它。NimaAnimation 有一个 NimaController 的抽象类,但不幸的是它没有任何 dispose 函数来停止它。
我因此面临的问题是性能问题。我什至尝试使用性能叠加来观察内存使用情况,我确实注意到动画没有被关闭,即使我导航到新屏幕,它也会继续在后端渲染。我为此编写的代码是:
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:maui/screens/tab_home.dart';
import 'package:nima/nima_actor.dart';
class WelcomeScreen extends StatefulWidget {
@override
State createState() => new WelcomeScreenState();
}
class WelcomeScreenState extends State<WelcomeScreen> {
bool delayed;
var animatecontrol = null;
NimaController nimaController;
NimaActor nima ;
void initState() {
super.initState();
nima = new NimaActor(
"assets/quack",
alignment: Alignment.center,
fit: BoxFit.scaleDown,
animation: 'welcome with hello',
mixSeconds: 0.2,
);
new Future.delayed(const Duration(milliseconds: 6200), () {
Navigator.of(context).pushReplacementNamed('/tab');
setState(() {
nima.controller;
delayed = true;
});
});
}
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
MediaQueryData media = MediaQuery.of(context);
var size = media.size;
// TODO: implement build
return (delayed == true)
? new TabHome()
: new Scaffold(
body: new Container(
decoration: new BoxDecoration(
color: Colors.purple,
),
child: new Stack(
alignment: AlignmentDirectional.bottomCenter,
children: <Widget>[
new Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new AspectRatio(
aspectRatio: size.height > size.width ? 1.5 : 3.8,
child: nima,
),
])
])));
}
}
解决方案
Nima Animator 具有暂停和完成的属性。这些可以帮助控制动画状态。有关详细信息,请参阅此链接(示例):
https://github.com/2d-inc/Nima-Flutter/blob/master/example/hop/lib/main.dart
推荐阅读
- regex - 通过分隔符拆分 CLOB 数据时面临问题
- macos - net.LookUpHost() 使用 os.Hostname() 后没有输出这样的主机
- laravel - VSCODE php Intelephense 查找显示重复项的引用
- java - 加载更多 Instagram 评论和点赞
- java - 以下程序的输出给我,它只是没有点击。答案是 6 3,我显然不明白
- python - 为什么我要在 Django 中连接库路径?
- c# - Azure 存储队列中的“Execution Timeout Expired”消息 - 过去几天没有将数据库记录推送到搜索索引
- python - Python更改套接字窗口标题
- python - 在报告 Python 版本的复杂 Bash 表达式中使用“egrep”进行过滤
- html - html中间文本对齐