Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnimationController : The named parameter 'vsync' isn't defined. #63486

Closed
ishandeveloper opened this issue Aug 11, 2020 · 14 comments
Closed

AnimationController : The named parameter 'vsync' isn't defined. #63486

ishandeveloper opened this issue Aug 11, 2020 · 14 comments

Comments

@ishandeveloper
Copy link

It has been around 5 days since I updated to the 1.21.0-8.0.pre.76 version of flutter. I was trying to add an AnimationController to one of the widgets of my app, and when I tried to pass a TickerProvider to the vsync parameter, the dart analyzer started throwing up an error that The named parameter 'vsync' isn't defined.

If I don't pass a vsync paramter however, the flutter engine will throw up an assertion error that no vsync is passed. I tried to ignore the errors and running directly in debug mode, and the app works just fine. But, it throws up these random errors and just wouldn't allow me to use my IDE's built in debugger or dart devTools.

I tried a similar thing before I had upgraded to flutter 1.20 release, and it worked just perfectly, as you'd expect it to.

    • Flutter version 1.21.0-8.0.pre.76 at C:\flutter
    • Framework revision 6d487355a3 (5 days ago), 2020-08-05 20:21:02 -0700
    • Engine revision d728f691f4
    • Dart version 2.10.0 (build 2.10.0-3.0.dev d5ff386abe)

Steps to Reproduce

  1. Create a new flutter project.
  2. Add a stateful widget with SingleTickerProviderStateMixin
  3. override the initState method and Initialize an AnimationController, and pass vsync:this as a parameter.

or you can just copy-paste this code from below or this dartPad.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: VsyncIssue(),
    );
  }
}

class VsyncIssue extends StatefulWidget {
  @override
  _VsyncIssueState createState() => _VsyncIssueState();
}

class _VsyncIssueState extends State<VsyncIssue>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;

  @override
  void initState() {
    _animationController =
        AnimationController(duration: Duration(milliseconds: 500), vsync: this);
    _animationController.forward();
_animationController.addListener(() => setState(() {}));
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          color: Colors.black,
          width: _animationController.value * 100,
          height: _animationController.value * 100,
        ),
      ),
    );
  }
}
Screenshots

Logs

flutter analyze --verbose

[ +271 ms] executing: [C:\src\flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[ +137 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +1 ms] 6d487355a380e6e4a285bdc47c2e7dab3fdb557f
[   +2 ms] executing: [C:\src\flutter/] git tag --contains HEAD
[ +543 ms] Exit code 0 from: git tag --contains HEAD
[   +4 ms] executing: [C:\src\flutter/] git describe --match *.*.* --first-parent --long --tags
[ +198 ms] Exit code 0 from: git describe --match *.*.* --first-parent --long --tags
[   +1 ms] 1.21.0-7.0.pre-76-g6d487355a3
[  +24 ms] executing: [C:\src\flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[  +83 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[   +1 ms] origin/master
[   +1 ms] executing: [C:\src\flutter/] git ls-remote --get-url origin
[ +108 ms] Exit code 0 from: git ls-remote --get-url origin
[   +8 ms] https://github.com/flutter/flutter.git
[ +148 ms] executing: [C:\src\flutter/] git rev-parse --abbrev-ref HEAD
[ +105 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[   +1 ms] master
[ +202 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[  +18 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[  +51 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[  +12 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +5 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[  +13 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[  +13 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[ +158 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[  +18 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update.
[  +15 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[  +26 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[  +32 ms] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[   +2 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[  +28 ms] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[  +32 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[   +7 ms] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +24 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[  +15 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[  +13 ms] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[   +2 ms] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[ +560 ms] Generating
D:\Projects\Collaborations\Flutter-Issues\animvsync\android\app\src\main\java\io\flutter\plugins\GeneratedPluginRegistrant.java      
[+1868 ms] dart --disable-dart-dev C:\src\flutter\bin\cache\dart-sdk\bin\snapshots\analysis_server.dart.snapshot
--disable-server-feature-completion --disable-server-feature-search --sdk C:\src\flutter\bin\cache\dart-sdk
[  +64 ms] ==> {"id":"1","method":"server.setSubscriptions","params":{"subscriptions":["STATUS"]}}
[   +8 ms] ==>
{"id":"2","method":"analysis.setAnalysisRoots","params":{"included":["D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync"],"excluded":[]}}
[  +33 ms] Analyzing animvsync...
[ +808 ms] <== {"event":"server.connected","params":{"version":"1.28.0","pid":23652}}
[  +76 ms] <== {"id":"1"}
[+1337 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\pubspec.yaml","errors":[]}}    
[  +23 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\android\\app\\src\\debug\\AndroidManifest.xml","errors":[]}}
[   +3 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\android\\app\\src\\main\\AndroidManifest.xml","errors":[]}}
[  +18 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\android\\app\\src\\profile\\AndroidManifest.xml","errors":[]}}
[  +89 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\build\\app\\intermediates\\bundle_manifest\\debug\\processDebugManifest\\bundle-manifest\\AndroidManifest.xml","errors":[]}}
[ +107 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\build\\app\\intermediates\\instant_app_manifest\\debug\\AndroidManifest.xml","errors":[]}}
[  +29 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\build\\app\\intermediates\\merged_manifests\\debug\\AndroidManifest.xml","errors":[]}}
[ +680 ms] <== {"id":"2"}
[+6773 ms] <== {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
[  +38 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\lib\\main.dart","errors":[]}}  
[+2815 ms] <==
{"event":"analysis.errors","params":{"file":"D:\\Projects\\Collaborations\\Flutter-Issues\\animvsync\\test\\widget_test.dart","errors":[]}}
[ +304 ms] <== {"event":"server.status","params":{"analysis":{"isAnalyzing":false}}}
[  +49 ms] Analyzing animvsync... (completed in 13.1s)
[   +4 ms] No issues found! (ran in 13.2s)
[  +35 ms] "flutter analyze" took 16,318ms.
[ +301 ms] ensureAnalyticsSent: 269ms
[   +4 ms] Running shutdown hooks
[  +10 ms] Shutdown hooks complete
[  +13 ms] exiting with code 0

flutter doctor -v

[√] Flutter (Channel master, 1.21.0-8.0.pre.76, on Microsoft Windows [Version 10.0.19041.388], locale en-US)
    • Flutter version 1.21.0-8.0.pre.76 at C:\src\flutter
    • Framework revision 6d487355a3 (5 days ago), 2020-08-05 20:21:02 -0700
    • Engine revision d728f691f4
    • Dart version 2.10.0 (build 2.10.0-3.0.dev d5ff386abe)

 
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at C:\Users\ishan\AppData\Local\Android\sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java     
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio1
    • Flutter plugin version 48.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.47.3)
    • VS Code at C:\Users\ishan\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.13.2

[√] Connected device (3 available)
    • GM1911 (mobile)  • 192.168.1.4:5555 • android-arm64  • Android 10 (API 29)
    • Web Server (web) • web-server       • web-javascript • Flutter Tools
    • Chrome (web)     • chrome           • web-javascript • Google Chrome 84.0.4147.105

• No issues found!
@befora
Copy link

befora commented Aug 11, 2020

animation_controller.dart

  AnimationController({
    double? value,
    this.duration,
    this.reverseDuration,
    this.debugLabel,
    this.lowerBound = 0.0,
    this.upperBound = 1.0,
    this.animationBehavior = AnimationBehavior.normal,
    required TickerProvider vsync,
  }) : assert(lowerBound != null),
       assert(upperBound != null),
       assert(upperBound >= lowerBound),
       assert(vsync != null),
       _direction = _AnimationDirection.forward {
    _ticker = vsync.createTicker(_tick);
    _internalSetValue(value ?? lowerBound);
  }

The "required" is missing @ annotation.

@ishandeveloper
Copy link
Author

@sethchhim Nice observation, I just saw that, yep, it's missing an '@' annotation in

line 242 of animation_controller.dart

to be specific

Replacing required TickerProvider vsync, with @required TickerProvider vsync fixes the issue. Wondering when this will be fixed for the master channel by a PR.

@TahaTesser
Copy link
Member

Hi @sethchhim
Please check this #63088 (comment)
I see there's an open issue addressing the case you described. #63088
Please follow up on that issue, I'm closing the current one as a duplicate.
If you disagree, please write in the comments and I will reopen it.
Thank you

@oemdaro
Copy link

oemdaro commented Oct 2, 2020

This issue happend again in Channel stable, 1.22.0.

➜ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.0, on Mac OS X 10.15.6 19G2021, locale en-KH)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.49.2)
[✓] Connected device (1 available)

• No issues found!

@TahaTesser
Copy link
Member

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

@GrahamDi
Copy link

GrahamDi commented Oct 2, 2020

We can but this looks like a simple regression in Flutter channel stable 1.22.0

The problem is exactly as described above by @sethchhim and confirmed by @ishandeveloper , there is an @ missing from required on line 242 of C:\flutter\packages\flutter\lib\src\animation\animation_controller.dart

I have just upgraded to 1.22.0 and now get this error, adding the @ fixes it.
Here is flutter doctor:
flutter doctor -v
[√] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.20226.1000], locale en-ZA)
• Flutter version 1.22.0 at C:\flutter
• Framework revision d408d30 (3 days ago), 2020-09-29 11:49:17 -0700
• Engine revision 5babba6
• Dart version 2.10.0

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at D:\Android\Sdk
• Platform android-30, build-tools 29.0.2
• ANDROID_HOME = D:\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin version 49.0.2
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.49.2)
• VS Code at C:\Users\dicki\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.15.0

[√] Connected device (1 available)
• FIG LX1 (mobile) • HBEDU18117010246 • android-arm64 • Android 9 (API 28)

• No issues found!

@TahaTesser
Copy link
Member

Hi @GrahamDi
I just tried the code sample on the latest stable there is no issue

code sample
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: VsyncIssue(),
    );
  }
}

class VsyncIssue extends StatefulWidget {
  @override
  _VsyncIssueState createState() => _VsyncIssueState();
}

class _VsyncIssueState extends State<VsyncIssue>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;

  @override
  void initState() {
    _animationController =
        AnimationController(duration: Duration(milliseconds: 500), vsync: this);
    _animationController.forward();
    _animationController.addListener(() => setState(() {}));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          color: Colors.black,
          width: _animationController.value * 100,
          height: _animationController.value * 100,
        ),
      ),
    );
  }
}
Launching lib\main.dart on Android SDK built for x86 64 in debug mode...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Connecting to VM Service at ws://127.0.0.1:57676/yvOAYRujnYk=/ws
D/EGL_emulation( 5499): eglMakeCurrent: 0x7d14942f7400: ver 2 0 (tinfo 0x7d1495d64840)
D/eglCodecCommon( 5499): setVertexArrayObject: set vao to 0 (0) 1 0

flutter doctor -v
[✓] Flutter (Channel stable, 1.22.0, on Microsoft Windows [Version 10.0.19041.508], locale en-US)
    • Flutter version 1.22.0 at C:\Code\flutter_stable
    • Framework revision d408d302e2 (3 days ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Code\sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = C:\Code\sdk
    • Java binary at: C:\Code\android-studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✓] Android Studio (version 4.0)
    • Android Studio at C:\Code\android-studio
    • Flutter plugin version 50.0.1
    • Dart plugin version 193.7547
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.49.2)
    • VS Code at C:\Users\Taha\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.15.0

[✓] Connected device (2 available)
    • RMX2001 (mobile)                      • EUYTFEUSQSRGDA6D • android-arm64 • Android 10 (API 29)
    • Android SDK built for x86 64 (mobile) • emulator-5554    • android-x64   • Android 9 (API 28) (emulator)

• No issues found!

@ishandeveloper
Copy link
Author

Hey there, I'm the one who opened this issue earlier and saw a notification, cuz somone pinged me.

I'm not near my PC, rn. I will share the flutter doctor -v results once I reach home. But, I've been using the animation controller in one of my production projects (the one with which I initially encountered this issue), and I can confirm that this issue does not occur in the stable channel.

However a week ago when I switched to the beta and then later on the to the master channel to test out Flutter Web, This issue was again reproducible on that production project, which was working fine in the stable channel.

I will share more logs and other details, once I reach back home.

@GrahamDi
Copy link

GrahamDi commented Oct 2, 2020

I still see this issue unless I add the @ back at line 242 of animation_controller.dart.
Seems the @ was removed (in this commit a7e868d https://github.com/flutter/flutter/blob/a7e868dd876f4b84462cc29fa2dd4092280a1d7a/packages/flutter/lib/src/animation/animation_controller.dart) two months ago.
I also see comments (see discussion from this point down: #62485 (comment)) regarding the @ being removed (two months ago) and causing issues with the IDE...then not causing them. All I am saying is that I am experiencing them having upgraded to 1.22.0

I can't comment on why you guys are not seeing it. I don't use anything other than stable so swapping and swapping back (which weirdly seems to fix some people's problems) is not something I do.

I use VSCode only.

Update
Also looks like restarting the IDE after the Flutter upgrade makes the problem go away. :-)

@oemdaro
Copy link

oemdaro commented Oct 3, 2020

Seems flutter upgrade have problems. I remove old directory and download a fresh one, it's working fine.

@allansrc
Copy link

allansrc commented Oct 5, 2020

So guys, this happened to me also. but I do not recomend to add "@" on animation_controller.dart, as set before migrate animation to null safety

Just run flutter upgrade then restart your IDE/TextEditor fully.

@dr3tt
Copy link

dr3tt commented Oct 30, 2020

This happened to me right now after I switched back from beta to stable channel.
I solved running the command flutter clean.

@flutterq

This comment was marked as spam.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants