'Flutter: Unable to migrate to null safety
I am following this guide to migrate my project to null safety: https://dart.dev/null-safety/migration-guide
But I am facing this issue with the dart migrate
command :
FileSystemException(path=C:\Program Files\Dart\dart-sdk\version; message=Cannot open file)
#0 _PhysicalFile.readAsStringSync (package:analyzer/file_system/physical_file_system.dart:184:7)
#1 FolderBasedDartSdk.languageVersion (package:analyzer/src/dart/sdk/sdk.dart:399:12)
#2 ContextBuilder.findSdk (package:analyzer/src/context/builder.dart:271:40)
#3 ContextBuilder.createSourceFactoryFromWorkspace (package:analyzer/src/context/builder.dart:218:19)
#4 ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:120:9)
#5 ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:94:37)
#6 new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:55:36)
#7 MigrationCliRunner.contextCollection (package:nnbd_migration/migration_cli.dart:544:28)
#9 MigrationCliRunner.run (package:nnbd_migration/migration_cli.dart:703:9)
#10 MigrateCommand.run (package:nnbd_migration/migration_cli.dart:185:72)
#11 CommandRunner.runCommand (package:args/command_runner.dart:196:27)
#12 DartdevRunner.runCommand (package:dartdev/dartdev.dart:199:30)
#13 CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#14 new Future.sync (dart:async/future.dart:218:31)
#15 CommandRunner.run (package:args/command_runner.dart:112:14)
#16 runDartdev (package:dartdev/dartdev.dart:53:29)
#17 main (file:///C:/b/s/w/ir/cache/builder/src/third_party/dart/pkg/dartdev/bin/dartdev.dart:11:9)
#18 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:279:32)
#19 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
dart version:
Dart SDK version: 2.12.1 (stable) (Wed Mar 10 10:18:47 2021 +0100) on "windows_x64"
flutter version:
Flutter 2.0.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8962f6dc68 (3 days ago) • 2021-03-11 13:22:20 -0800
Engine • revision 5d8bf811b3
Tools • Dart 2.12.1
Update SDK constraints:
environment:
sdk: ">=2.12.0 <3.0.0"
And my Environment Variables consist of this path: <PATH_TO_SDK>\flutter\bin
Solution 1:[1]
Open Registry Editor in Windows and search (Ctrl + F) for "DART_SDK". Update the entry if it is incorrect.
Restart your PC for any changes to remain.
Solution 2:[2]
Download the latest Dart and put the dart-sdk under c:/program files/DART. It seems the dart migrate tries to locate the sdk under that folder
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | david weng |