flutter - 无法使用颤振动画包创建动画
问题描述
我使用 flutter_animator 包创建了一个颤振项目:^3.2.0 但在运行应用程序时出现错误,这让我很困惑。我已经按照文档做了,但仍然无法运行。我也尝试使用 animate_do 包,运行时出现同样的错误。这是我的代码:
import 'package:ayo_masak/utils/importutils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animator/flutter_animator.dart';
import 'package:get/get.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Ayo Masak',
debugShowCheckedModeBanner: false,
theme: AppThemeData.lightTheme,
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
GlobalKey<CrossFadeABState> crossFadeAnimation =
GlobalKey<CrossFadeABState>();
GlobalKey<AnimatorWidgetState> basicAnimation =
GlobalKey<AnimatorWidgetState>();
GlobalKey<InOutAnimationState> inOutAnimation =
GlobalKey<InOutAnimationState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter Animator'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Padding(padding: EdgeInsets.only(top: 20)),
CrossFadeAB(
key: crossFadeAnimation,
childA: const Text('A', style: TextStyle(fontSize: 20)),
childB: const Text('B', style: TextStyle(fontSize: 20)),
),
const Padding(padding: EdgeInsets.only(top: 20)),
TextButton(
onPressed: () {
crossFadeAnimation.currentState!.cross();
},
child: const Text(
'Cross Animate',
style: TextStyle(fontSize: 20),
),
),
BounceIn(
key: basicAnimation,
child: const Text(
'BounceIn',
style: TextStyle(fontSize: 20),
),
),
const Padding(padding: EdgeInsets.only(top: 20)),
TextButton(
onPressed: () {
basicAnimation.currentState!.forward();
},
child: const Text(
'Animate Bounce',
style: TextStyle(fontSize: 20),
),
),
const Padding(padding: EdgeInsets.only(top: 40)),
InOutAnimation(
key: inOutAnimation,
child: const Text(
'In & Out',
style: TextStyle(fontSize: 20),
),
inDefinition: FadeInAnimation(),
outDefinition: BounceOutDownAnimation(),
),
const Padding(padding: EdgeInsets.only(top: 20)),
TextButton(
onPressed: () {
if (inOutAnimation.currentState!.status !=
InOutAnimationStatus.Out) {
inOutAnimation.currentState!.animateOut();
} else {
inOutAnimation.currentState!.animateIn();
}
},
child: const Text(
'Animate In & Out',
style: TextStyle(fontSize: 20),
),
),
],
),
),
);
}
}
这是我运行应用程序后得到的日志,有很多错误。奇怪的是,在我的代码中根本没有检测到错误。
Launching lib/main.dart on ASUS X00RD in debug mode...
Running Gradle task 'assembleDebug'...
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:85:16: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
if (widget.definition.needsWidgetSize && widgetSize == null) {
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:87:25: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
opacity: widget.definition.preRenderOpacity,
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:88:23: Error: The getter 'child' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
child: widget.child,
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:91:16: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
if (widget.definition.needsScreenSize && screenSize == null) {
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:93:25: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
opacity: widget.definition.preRenderOpacity,
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:94:23: Error: The getter 'child' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
child: widget.child,
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:97:44: Error: The getter 'child' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
return animator!.build(context, widget.child);
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:102:45: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
animator!.setAnimationDefinition(widget.definition);
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:103:16: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
if (widget.definition.needsWidgetSize ||
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:104:16: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
widget.definition.needsScreenSize) {
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:111:22: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
if (widget.definition.needsWidgetSize) {
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:115:22: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
if (widget.definition.needsScreenSize) {
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:123:32: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
handlePlayState(widget.definition.preferences.autoPlay);
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/animator_widget.dart:130:30: Error: The getter 'definition' isn't defined for the class 'T Function()'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'definition'.
handlePlayState(widget.definition.preferences.autoPlay);
^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:38:21: Error: The getter 'autoPlay' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'autoPlay'.
status = widget.autoPlay;
^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:60:30: Error: The getter 'inDefinition' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'inDefinition'.
definition: widget.inDefinition,
^^^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:61:25: Error: The getter 'child' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
child: widget.child,
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:66:30: Error: The getter 'outDefinition' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'outDefinition'.
definition: widget.outDefinition,
^^^^^^^^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:67:25: Error: The getter 'child' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
child: widget.child,
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart:70:23: Error: The getter 'child' isn't defined for the class 'InOutAnimation Function()'.
- 'InOutAnimation' is from 'package:flutter_animator/widgets/in_out_animation.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/in_out_animation.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'child'.
return widget.child;
^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart:55:22: Error: The getter 'childA' isn't defined for the class 'CrossFadeAB Function()'.
- 'CrossFadeAB' is from 'package:flutter_animator/widgets/specials/cross_fade_a_b.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'childA'.
? widget.childA
^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart:56:48: Error: The getter 'childA' isn't defined for the class 'CrossFadeAB Function()'.
- 'CrossFadeAB' is from 'package:flutter_animator/widgets/specials/cross_fade_a_b.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'childA'.
: animatorA!.build(context, widget.childA),
^^^^^^
../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart:57:65: Error: The getter 'childB' isn't defined for the class 'CrossFadeAB Function()'.
- 'CrossFadeAB' is from 'package:flutter_animator/widgets/specials/cross_fade_a_b.dart' ('../../../Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_animator-3.2.0/lib/widgets/specials/cross_fade_a_b.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'childB'.
if (animatorB != null) animatorB!.build(context, widget.childB),
^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script '/Users/macbook pro/Documents/Development/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1005
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/macbook pro/Documents/Development/flutter/bin/flutter'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 26s
解决方案
我成功删除了我的flutter sdk并重新下载了flutter sdk,终于动画可以运行了。不知何故与以前的颤振SDK。
推荐阅读
- c# - 如何将假货注入 DI 容器?
- html - 使用 flexbox,在 flexitem 内的 div 上显示滚动条
- java - 如何在 TaskExecutionAutoConfiguration 旁边创建额外的 TaskExecutor?
- javascript - 使用 NodeJS 在 Firebase 数据库中创建 Schema
- javascript - “数字”类型的参数不可分配给“持续时间构造器”类型的参数
- android - 如何区分 Google Fit Api 中手动添加的步骤和传感器记录的步骤
- facebook - Facebook Messenger 链接按钮 - 避免留下 Facebook 消息
- angularjs - Angularjs - 如何为来自 ng repeat 的动态数据展开过滤器上的折叠 div
- python - 是否可以在请求模块中取消长时间运行的 HTTP 请求?
- firebase - 可以从应用程序根目录更改 firebase-messaging-sw.js 位置,还是隐藏其密钥?由于 SENDER_ID 密钥已公开/公开