You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vsync is not detected as a named parameter in the AnimatedBuilder class #2793
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:
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.
DanTup, thank for your answer. I'm on the channel beta and it is up to date as the following image shows:
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.
Perhaps this information helps to reproduce the bug.
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.
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.
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!
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?
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).
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.
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.
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: langtestdescription: A new Flutter project.version: 1.0.0+1environment:
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:flutteranalysis_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.
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.
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.
Activity
DanTup commentedon Sep 15, 2020
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 newrequiredkeyword, 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.
cesarverdes commentedon Sep 15, 2020
DanTup, thank for your answer. I'm on the channel beta and it is up to date as the following image shows:
I realised something important related with the bug. The problem appears only when I paste the example code on the
main.dartfile of thelibfolder on a new just created Flutter project.If I close VSCode showing the
vsyncerror and open VSCode again (without doing anything more than close and open VSCode) thevsyncis interpreted correctly and the error disappear.Perhaps this information helps to reproduce the bug.
This is a useful workaround for me.
DanTup commentedon Sep 16, 2020
Can you reliably reproduce this? Can you share the exact steps?
I tried:
main.dartThis 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
vsyncparameter is now marked with therequiredkeyword (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.cesarverdes commentedon Sep 16, 2020
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:
In this case the issue appears and the
vsyncparameter 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.
DanTup commentedon Sep 17, 2020
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!
cesarverdes commentedon Sep 17, 2020
Thank you for your time and interest!
Glad I can help, at least in a very little improvement.
👍
Delay analysis server creation until after projects are created
DanTup commentedon Sep 21, 2020
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:
flutter createto create a new Flutter project in the empty folderThis seems to have the server in a sate where
requireddoesn't work. Restarting VS Code fixes it. Is there something in the Flutter project that activates support forrequired(maybe pubspec SDK constraint?)? If so, should it be automatically updating if it's created afterwards?Delay analysis server creation until after projects are created
bwilkerson commentedon Sep 21, 2020
@scheglov
If we're talking about the
requiredkeyword, then yes, there needs to be a high enough minimum SDK in thepubspec.yamlfile.It sounds like server might not be correctly recreating the contexts after a
pubspec.yamlfile is created.DanTup commentedon Sep 21, 2020
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
requiredkeyword is in the Flutter code, and not the users code - they are just calling the constructor that uses it).bwilkerson commentedon Sep 21, 2020
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.
scheglov commentedon Sep 21, 2020
requiredmeans something for a parameter when the library that calls the method with arequiredparameter is null safe. Otherwise, it is ignored. There is no yet version of the SDK where thenon-nullablefeature 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, usinganalysis_options.yamlfile.DanTup commentedon Sep 22, 2020
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 runpub get):pubspec.yaml
lib/main.dart
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:flutterimport andAnimationController.Now run
pub get. The original errors will disappear, but thevsyncerror will appear. Reloading the IDE will cause that to go away too. (note: Thenon-nullableexperiment is enabled in thepackage:flutteranalysis_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.
scheglov commentedon Sep 22, 2020
Yes, I believe that this is a bug. DAS should listen for
.dart_tool/package_config.jsonfile 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.DanTup commentedon Sep 23, 2020
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.