coc-flutter
coc-flutter copied to clipboard
Flutter run not working with null-safety flag
Describe the bug
More recent version of flutter implement the null safety feature, which throws out errors if not run with the --no-sound-null-safety
flag. When running flutter from the terminal this works as normal (even without the flag), however when using the inbuilt CocCommand flutter.run --no-sound-null-safety
there are errors which indicate that this flag isnt parsed.
There is only 1 version of flutter on my system (which I reinstalled using the stable channel).
Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (11 days ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
Error: Cannot run with sound null safety, because the following dependencies don't support null safety:
.....
lib/main.dart:230:23: Error: The parameter 'controller' can't have a value of 'null' because of its type 'TextEditingController', but the implicit default value is 'null'.
To Reproduce Steps to reproduce the behavior:
- run :CocCommand flutter.run --no-sound-null-safety
- it doesn't say anywhere that it's using the flag
Expected behavior I expect it to use the flag and work just like the normal terminal command.
Desktop (please complete the following information):
- OS: Windows 11
- Vim or Neovim: Neovim
- (Neo)vim version: NVIM v0.6.0
This is copy of https://github.com/iamcco/coc-flutter/issues/78 as it was noted there that a new ticket should be opened for this issue
That’s really weird, might be windows only perhaps.
Can you test what happen if you run with the —help
flag instead
But on a sidenote as I believe I also mentioned in the other ticket. If you don’t want to run in sound nullsafety mode you can opt out by putting // @dart = 2.11
at the top of your main.dart
which is way more convenient.
@Kavantix When I run with the --help
flag I get the below output, which indicates that --help
was parsed properly:
undefinedRun your Flutter app on an attached device.
Global options:
-h, --help Print this usage information.
...
I tried to do this on my linux machine with the same flutter version and the flutter run works without an issue, which leads me to believe that this is indeed a windows problem.
I also tried to add the // @dart = 2.11
parameter at the top of my main.dart
file but the issue I had still remained
Interesting, can you try running with --no-sound-null-safety -v
.
That the dart version comment doesn't work is even stranger, did you run without the flag after adding that line?
I just noticed that the documentation of the flag specifies that it works differently for flutter web:
--[no-]sound-null-safety Whether to override the inferred null safety mode. This allows null-safe libraries to depend on un-migrated (non-null safe) libraries. By default, Flutter mobile & desktop applications will attempt to run at the null safety level of their entrypoint library (usually lib/main.dart). Flutter web applications will default to sound null-safety, unless specifically configured.
Are you running on web?
I am running only on my android phone for both windows and linux.
That the dart version comment doesn't work is even stranger, did you run without the flag after adding that line?
I ran wthout the flag after commenting the dart version, so :CocCommand flutter.run
.
I also ran with --no-sound-null-safety -v
, the output of which I attached to this comment, but from having a quick glance it seems that the flag is indeed there. @Kavantix Let me know if I can provide any more diagnostic information.
log.txt
Well I have no idea why this would not work, or alternatively why it does work if you run directly from the console.
It is even passing the flag to the dart executable:
C:\Tools\flutter\bin\cache\dart-sdk\bin\dart.exe --disable-dart-dev C:\Tools\flutter\bin\cache\artifacts\engine\windows-x64\frontend_server.dart.snapshot --sdk-root C:\Tools\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk/ --incremental --target=flutter --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true --output-dill C:\Users\User\AppData\Local\Temp\flutter_tools.32742ab\flutter_tool.2b26a192\app.dill --packages c:\Users\User\Documents\Coding\Flutter\app\.dart_tool\package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build\c7922d95bf4a2462b75c84a97c312edb.cache.dill.track.dill --enable-experiment=alternative-invalidation-strategy --no-sound-null-safety
Can you try running directly from the console with the dart version comment and without --no-sound-null-safety
Can you try running directly from the console with the dart version comment and without
--no-sound-null-safety
Are you refferinig to the command you specified in https://github.com/iamcco/coc-flutter/issues/149#issuecomment-1002989751? I tried to run that but I dont think powershell can parse all the flags properly:
Error: Error when reading '.vm.profile=false': The system cannot find the file specified.
No I just mean flutter run
Running flutter run
from mthe terminal with the comment in the main.dart
file results in the application startinng normally (with an unsound null safety warning). Let me know if you want me to provide the full output
@brokoli18 could you try to check if coc-flutter is using the same flutter executable as when you run it manually.
It might also help if you could share the normal flutter output (instructions are in the issue template)