首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AnimationController未定义命名参数“vsync”

AnimationController未定义命名参数“vsync”
EN

Stack Overflow用户
提问于 2020-08-01 15:57:46
回答 16查看 35.4K关注 0票数 81

AnimationController停止工作,因为vsync不再是一个命名的参数。

这一行代码停止工作。

controller = AnimationController(duration: Duration(seconds: 3), vsync: this);

它现在显示了一个错误,它说:

代码语言:javascript
复制
The named parameter 'vsync' isn't defined.
Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'vsync'.dartundefined_named_parameter

我在两个不同的应用程序中使用了完全相同的代码,其中一个应用程序中,我删除了作为热修复程序的渐变文本动画,但在另一个应用程序中,我需要一个真正的修复程序。最近有人见过这个问题吗?

注意:

-This完全相同的代码已经运行了几个月,并且在更新后停止工作。

-The周围的类确实有:with TickerProviderStateMixin

代码语言:javascript
复制
class FadingText extends StatefulWidget {
  final String text;
  final int seconds;
  final TextStyle style;

  FadingText({this.text, this.seconds, this.style});

  @override
  _FadingTextState createState() => _FadingTextState();
}

class _FadingTextState extends State<FadingText> with TickerProviderStateMixin {
  AnimationController controller;
  Animation animation;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: FadeTransition(
        opacity: animation,
        child: Text(widget.text, style: widget.style,),
      ),
    );
  }

  @override
  void initState() {
    super.initState();

    controller = AnimationController(duration: Duration(seconds: widget.seconds), vsync: this);
    animation = Tween(begin: 0.5, end: 1.0).animate(controller);

    animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) { controller.reverse(); }
      else if (status == AnimationStatus.dismissed) { controller.forward(); }
    });

    controller.forward();
  }


  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

}
代码语言:javascript
复制
Flutter Doctor


[✓] Flutter (Channel master, 1.21.0-6.0.pre.140, on Mac OS X 10.15.5 19F101, locale en-MX)
    • Flutter version 1.21.0-6.0.pre.140 at /Users/luisharo/Developer/flutter
    • Framework revision 7884420a0a (25 hours ago), 2020-07-31 20:20:00 +0200
    • Engine revision 280bbfc763
    • Dart version 2.10.0 (build 2.10.0-2.0.dev bd528bfbd6)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/luisharo/Library/Android/sdk
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.8.4

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[✓] IntelliJ IDEA Community Edition (version 2019.2.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.8052

[✓] VS Code (version 1.47.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.1

[✓] Connected device (4 available)
    • JKM LX3 (mobile)       • 7MLNW19723003608                     • android-arm64  • Android 9 (API 28)
    • iPhone 11 Pro (mobile) • 675C24C4-7682-4DFE-8037-062893405EE7 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-5
      (simulator)
    • Web Server (web)       • web-server                           • web-javascript • Flutter Tools
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 84.0.4147.105

• No issues found!
EN

回答 16

Stack Overflow用户

回答已采纳

发布于 2020-08-03 12:32:17

在你的pubspec.yml

将此更改为:

代码语言:javascript
复制
environment:
  sdk: ">=2.8.0 <3.0.0"

flutter pub get

在Android中,使缓存无效并重新启动,应该是好的选择。

信贷:https://github.com/flutter/flutter/issues/62752#issuecomment-667744745

票数 126
EN

Stack Overflow用户

发布于 2020-08-18 00:54:34

所发生的事情是,@required语法是在空安全的推出过程中迁移到现在的required。这是有效的new-Dart,但是如果您在打开编辑器的情况下升级,它将有过时的构建规则。只需运行flutter clean并重新启动您的IDE,就可以做到这一点。

希望不需要重新启动你的电脑,改变互联网提供商,等等。

票数 35
EN

Stack Overflow用户

发布于 2020-08-08 17:20:05

有几件事情(不幸的是没有明确指出)可以帮助我解决这样的问题:

**编辑:我建议这样做,希望这个问题能在你到达列表末尾之前解决。

  • 运行颤振升级
  • 运行颤振发布获取
  • 运行颤振清除
  • 重新启动IDE
  • 更改颤振通道H 210,在本例中,将最小SDK版本从2.7.0改为2.8.0。H 212f 213

当然,这些策略中也有一些需要注意的。更有经验的开发人员肯定会提供更多的细节,但我没有遇到这种方法的问题。

票数 23
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63207206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档