AnimationController The named parameter 'vsync' isn't defined

31,806

Solution 1

In your pubspec.yml

change this to:

environment:
  sdk: ">=2.8.0 <3.0.0"

and flutter pub get

in Android Studio invalidate the cache and restart, you should be good to go.

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

Solution 2

What happened is that @required syntax was migrated during the rollout of null-safety to now just be required. This is valid new-Dart, but if you upgrade with your editor open, it will have stale build rules. Simply run flutter clean and restart your IDE, and that should do it.

Hopefully no need to restart your computer, change internet providers, etc.

Solution 3

A few things (unfortunately not pinpointed) that help me with issues like this:

**edit: I would recommend doing these in order, hopefully the issue will be solved before you reach the end of the list.

  • run flutter upgrade
  • run flutter pub get
  • run flutter clean
  • restart IDE
  • change flutter channel
  • and in this case, change minimum SDK version from 2.7.0 to 2.8.0.

There are, of course, caveats to a few of these tactics. More experienced developers would surely have more details to offer, but I haven't encountered issues with this approach.

Solution 4

Had the same issue after upgrading flutter. Restarting the IDE fixed the problem.

Solution 5

I ran into the same issue when I upgraded to Flutter 1.22.

I am using VS Code.

Simply run: Flutter Clean in the Terminal and restart your IDE. That should fix the problem!

Share:
31,806

Related videos on Youtube

Chamanhm
Author by

Chamanhm

Updated on November 30, 2021

Comments

  • Chamanhm
    Chamanhm over 2 years

    AnimationController stopped working because somehow vsync is not a named parameter anymore.

    This line of code stopped working.

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

    It now shows an error saying:

    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
    

    I use this exact same code in two different apps, in one of them I just removed the fading text animation as a hot fix, but on the other app I need a real fix. Has anyone seen this problem recently?

    Note:

    -This exact same code has been working for months and stopped working after an update.

    -The surrounding class does have: with TickerProviderStateMixin

    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();
      }
    
    }
    
    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!
    
    • Mariano Zorrilla
      Mariano Zorrilla almost 4 years
      Could you post your class constructor? And where you tried to implement your Controller?
    • Chamanhm
      Chamanhm almost 4 years
      Hi Mariano, I posted an edit with the whole class.
    • Mariano Zorrilla
      Mariano Zorrilla almost 4 years
      could you also post your "flutter doctor -v"? Is the same issue happening using the single ticker provider?
    • Rémi Rousselet
      Rémi Rousselet almost 4 years
      Do you have another class with the same name maybe?
    • Chamanhm
      Chamanhm almost 4 years
      I added the results of flutter doctor -v... also checked that the class is not duplicated.
    • Chamanhm
      Chamanhm almost 4 years
      Same error if trying with SingleTickerProviderStateMixin
    • Quentin Aoustin
      Quentin Aoustin almost 4 years
      I am currently running into the same issue. This is probably a bug introduce since the last update... Try to open an issue on the flutter GitHub page it should be fixed quickly if this issue is as spread as I think. By checking here : github.com/flutter/flutter/commit/… You can see the modifications made 4 days ago.
  • sultanmyrza
    sultanmyrza almost 4 years
    to "invalidate the cache and restart" in android studio click (File -> Invalidate Caches/Restart)
  • Quyen Anh Nguyen
    Quyen Anh Nguyen over 3 years
    As for me I need one more step is reload IDE :D Thanks, it works like a charm.
  • Elia Weiss
    Elia Weiss over 3 years
    I first change sdk: ">=2.8.0 <3.0.0" in pubspec.yml and then a restart, not sure which one solved the issue.
  • Admin
    Admin over 3 years
    Only doing the first four steps solved the issue.
  • Nouman Hanif
    Nouman Hanif about 3 years
    for VSCode, do 'Restart Analysis Server', ctrl+shift+p to bring up the command palette and type 'analysis' to search for it. This will save you from restarting the IDE
  • Hashem Aboonajmi
    Hashem Aboonajmi almost 3 years
    Editor Restart fixed it
  • Jan
    Jan over 2 years
    This solved the issue for me, thank