Skip to content

vsync is not detected as a named parameter in the AnimatedBuilder class #2793

Closed

Description

@cesarverdes

Copying and pasting the example of the AnimatedBuilder class documentation page the vsync paramameter is not recognized and detected as an error in this piece of code:

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 10),
      vsync: this,
    )..repeat();
  }

as is shown in the following image:
bug

The constructor signature is interpreted by VSCode as:
bug2

but the definition in the animation_controller.dart file into the packages/flutter/lib/src/animation is:

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);
 }

Activity

  1. DanTup commented on Sep 15, 2020

    @DanTup
    Member

    Can you confirm which Flutter channel you're on? And if not already on the latest version of that channel, try upgrading (with flutter upgrade)? I saw this error a few weeks ago - it seemed to be that the SDK didn't recognise the new required keyword, but after updating I haven't seen it again.

    You may need to reload VS Code after updating to ensure it starts a new version of the analysis server.

  2. added
    awaiting infoRequires more information from the customer to progress
    on Sep 15, 2020
  3. cesarverdes commented on Sep 15, 2020

    @cesarverdes
    Author

    DanTup, thank for your answer. I'm on the channel beta and it is up to date as the following image shows:

    bug3

    I realised something important related with the bug. The problem appears only when I paste the example code on the main.dart file of the lib folder on a new just created Flutter project.

    If I close VSCode showing the vsync error and open VSCode again (without doing anything more than close and open VSCode) the vsync is interpreted correctly and the error disappear.

    bug4

    Perhaps this information helps to reproduce the bug.

    This is a useful workaround for me.

  4. DanTup commented on Sep 16, 2020

    @DanTup
    Member

    Can you reliably reproduce this? Can you share the exact steps?

    I tried:

    • flutter channel beta && flutter upgrade
    • flutter create mytest
    • cd mytest && code .
    • paste the full code from the doc linked above over the default main.dart

    This didn't seem to reproduce the issue though. Is it possible you'd upgraded Flutter while VS Code was open, so it may have been running an older version of the analysis server initially?

    The vsync parameter is now marked with the required keyword (which is new - it used to be an annotation) but as far as I can tell the version of the analysis server in beta fully understands this.

  5. cesarverdes commented on Sep 16, 2020

    @cesarverdes
    Author

    I repeat exactly your steps and the issue do not appear (the 'vsync' parameter was recognized without error).

    I realized that the problem appear when I create the project from VSCode.

    Please, could you try this steps:

    • flutter channel beta && flutter upgrade
    • code
    • press Ctrl+Shift+P and run the '>Flutter:New Project' command
    • enter 'mytest' as the name of the project and select a parent directory
    • paste the full code from the doc linked above over the default main.dart

    In this case the issue appears and the vsync parameter is marked as an error.

    It seems that there is a difference between running the command line 'flutter create mytest' and create the project from within VSCode with the '>Flutter:New Project' command.

    I hope you can replicate the issue.

    Best regards.

  6. DanTup commented on Sep 17, 2020

    @DanTup
    Member

    Yes, I was able to reproduce this. I think it's related to starting the analysis server before the project has been fully created. I'll do some additional testing - thanks!

  7. added
    in flutterRelates to running Flutter apps
    and removed
    awaiting infoRequires more information from the customer to progress
    on Sep 17, 2020
  8. added this to the v3.15.0 milestone on Sep 17, 2020
  9. cesarverdes commented on Sep 17, 2020

    @cesarverdes
    Author

    Thank you for your time and interest!

    Glad I can help, at least in a very little improvement.

    👍

  10. added a commit that references this issue on Sep 21, 2020
    838ad2b
  11. DanTup commented on Sep 21, 2020

    @DanTup
    Member

    I've managed to fix this by not creating the analysis server until after any new project creation is complete (creating it before had caused other issues in the past, so doing this might avoid other potential problems).

    @bwilkerson I'm not sure if there's a server issue here worth fixing though.

    What was essentially happening before is:

    • Create an empty folder
    • Spawn an analysis server and set its analysis root to the empty folder
    • Use flutter create to create a new Flutter project in the empty folder

    This seems to have the server in a sate where required doesn't work. Restarting VS Code fixes it. Is there something in the Flutter project that activates support for required (maybe pubspec SDK constraint?)? If so, should it be automatically updating if it's created afterwards?

  12. added a commit that references this issue on Sep 21, 2020
    a85d62e
  13. bwilkerson commented on Sep 21, 2020

    @bwilkerson

    @scheglov

    Is there something in the Flutter project that activates support for required (maybe pubspec SDK constraint?)?

    If we're talking about the required keyword, then yes, there needs to be a high enough minimum SDK in the pubspec.yaml file.

    If so, should it be automatically updating if it's created afterwards?

    It sounds like server might not be correctly recreating the contexts after a pubspec.yaml file is created.

  14. DanTup commented on Sep 21, 2020

    @DanTup
    Member

    there needs to be a high enough minimum SDK in the pubspec.yaml file

    Right, that seems to all add up then.

    Though I guess this means that Flutter users with existing projects are expected to add minimum SDK constraints to their own pubspecs when upgrading Flutter? (the required keyword is in the Flutter code, and not the users code - they are just calling the constructor that uses it).

  15. bwilkerson commented on Sep 21, 2020

    @bwilkerson

    That's a harder question. For any given language feature (such as null-safety) a library that's opted out should be able to reference code in a library that's opted in, so theoretically users should not need to update their own SDK constraints to use a package with different constraints (as long as they overlap). However, Flutter packages are in a strange place because they're part of the Flutter SDK. Technically, I suppose, when a user upgrades Flutter they should update their SDK constraints to indicate that they're now depending on the version to which they updated. But I don't believe that we support the required SDK version yet. I'm not entirely sure how this should be working.

    Perhaps we should open an issue in the language repo (https://github.com/dart-lang/language) to clarify.

  16. scheglov commented on Sep 21, 2020

    @scheglov

    required means something for a parameter when the library that calls the method with a required parameter is null safe. Otherwise, it is ignored. There is no yet version of the SDK where the non-nullable feature is turned on by default. So, the only way to get it is not have high enough SDK version (2.10.0) and to turn the experiment on for the consumer package, using analysis_options.yaml file.

  17. DanTup commented on Sep 22, 2020

    @DanTup
    Member

    Ok, I found an easier way to reproduce this, and it may be related to fetching packages while the analysis server is already live.

    Create a simple Flutter "project" that creates an AnimationController (but don't run pub get):

    pubspec.yaml

    name: langtest
    description: A new Flutter project.
    version: 1.0.0+1
    
    environment:
      sdk: ">=2.8.0 <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter

    lib/main.dart

    import 'package:flutter/material.dart';
    
    final a = AnimationController(vsync: null);

    Open and analyze it (using the SDK from Flutter - I'm using 1.22.0-12.0.pre). You'll get errors on the package:flutter import and AnimationController.

    Now run pub get. The original errors will disappear, but the vsync error will appear. Reloading the IDE will cause that to go away too. (note: The non-nullable experiment is enabled in the package:flutter analysis_options.yaml).

    So it may be occurring when a package is initially unavailable, and then becomes available (via the packages file being updated) while the server is running.

    If that sounds like a bug and you want me to file an sdk issue, let me know.

  18. scheglov commented on Sep 22, 2020

    @scheglov

    Yes, I believe that this is a bug. DAS should listen for .dart_tool/package_config.json file changes, and recreate analysis contexts, so pick up new language versions for packages. As always with DAS these days I'm so-o-o hesitant to make any changes to it, because we know that we want to replace it.

  19. DanTup commented on Sep 23, 2020

    @DanTup
    Member

    Ok, I've filed an issue to track it (dart-lang/sdk#43532) though I'll leave it for to decide if it's worth fixing if it's in code that's being replaced. The original issue reported here when creating new projects has been resolved by having VS Code wait for packages to be fetched before spawning the analyzer. That doesn't solve all the instances of this, but at least solves the easy new-project case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions