简体   繁体   中英

Dart Null-Safety - Range Error when executing dart migrate to upgrade to new null safety

I'm having problems upgrading a custom package to null safety and am not finding any solutions or even the same problem when searching on here and any other platform.

When upgrading a custom package for Flutter 2.0 null-safety I'm using dart migrate as the guide proposes, but am getting a compiler Error.

But the error does not specify where it occurs nor is the errors description any help. I looked through the entire package to find any Array/List or inclusive range error, without any success.

I'm running out of ideas to fix this error and complete the upgrade to null-safety. Does someone have an idea what I can try to fix this error?

Error message :

dart migrate           
Migrating file_name

See https://dart.dev/go/null-safety-migration for a migration guide.

Note: more than one project found; migrating the top-level project.

Analyzing project...
[--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------]No analysis issues found.

Generating migration suggestions...
[--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------]

Compiling instrumentation information...
[--------------------|                                                                                                                                                                 ]RangeError (index): Invalid value: Not in inclusive range 0..12: 13
#0      List.[] (dart:core-patch/array.dart:268:52)
#1      BestPracticesVerifier._targetKindsFor (package:analyzer/src/error/best_practices_verifier.dart:1582:38)
#2      BestPracticesVerifier.visitAnnotation (package:analyzer/src/error/best_practices_verifier.dart:250:17)
#3      AnnotationImpl.accept (package:analyzer/src/dart/ast/ast.dart:280:49)
#4      NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#5      AnnotatedNodeImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:148:17)
#6      ClassDeclarationImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:1559:11)
#7      RecursiveAstVisitor.visitClassDeclaration (package:analyzer/dart/ast/visitor.dart:707:10)
#8      BestPracticesVerifier.visitClassDeclaration (package:analyzer/src/error/best_practices_verifier.dart:320:13)
#9      ClassDeclarationImpl.accept (package:analyzer/src/dart/ast/ast.dart:1536:49)
#10     NodeListImpl.accept (package:analyzer/src/dart/ast/ast.dart:7611:20)
#11     CompilationUnitImpl.visitChildren (package:analyzer/src/dart/ast/ast.dart:2141:21)
#12     RecursiveAstVisitor.visitCompilationUnit (package:analyzer/dart/ast/visitor.dart:731:10)
#13     CompilationUnitImpl.accept (package:analyzer/src/dart/ast/ast.dart:2134:49)
#14     LibraryAnalyzer._computeHints (package:analyzer/src/dart/analysis/library_analyzer.dart:281:10)
#15     LibraryAnalyzer.analyzeSync.<anonymous closure> (package:analyzer/src/dart/analysis/library_analyzer.dart:167:9)
#16     _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:397:8)
#17     LibraryAnalyzer.analyzeSync (package:analyzer/src/dart/analysis/library_analyzer.dart:166:13)
#18     LibraryAnalyzer.analyze (package:analyzer/src/dart/analysis/library_analyzer.dart:107:12)
#19     AnalysisDriver._computeResolvedLibrary2.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1416:65)
#20     PerformanceLog.run (package:analyzer/src/dart/analysis/performance_logger.dart:32:15)
#21     AnalysisDriver._computeResolvedLibrary2 (package:analyzer/src/dart/analysis/driver.dart:1402:20)
#22     AnalysisDriver._computeResolvedLibrary.<anonymous closure> (package:analyzer/src/dart/analysis/driver.dart:1395:15)
#23     _rootRun (dart:async/zone.dart:1354:13)
#24     _CustomZone.run (dart:async/zone.dart:1258:19)
#25     _runZoned (dart:async/zone.dart:1788:10)
#26     runZoned (dart:async/zone.dart:1710:10)
#27     NullSafetyUnderstandingFlag.enableNullSafetyTypes (package:analyzer/dart/element/null_safety_understanding_flag.dart:42:12)
#28     AnalysisDriver._computeResolvedLibrary (package:analyzer/src/dart/analysis/driver.dart:1394:40)
#29     AnalysisDriver.performWork (package:analyzer/src/dart/analysis/driver.dart:964:22)
#30     AnalysisDriverScheduler._run (package:analyzer/src/dart/analysis/driver.dart:2018:24)
<asynchronous suspension>

This appears to be a bug in the Dart SDK itself. This is tracked in dart-lang/sdk#46183 and was fixed in this commit .

Steps to try on your end:

  1. Run flutter upgrade to be sure you're on the latest release.
  2. If you are still encountering the issue after that, consider changing to Flutter's beta channel to get a more bleeding-edge SDK in order to run the migration tool, then switch back to the stable channel once you're done. You can do this by running flutter channel beta , then re-running the migration, then flutter channel stable to switch back.

I had the same issue, it is fixed in beta channel as stated in the cbracken's answer.

Also, in my case I had second Dart SDK (2.12) installed outside Flutter, so the issue appeared to be unresolved.

Make sure you are running dart migrate using dart included in your Flutter SDK Flutter/bin folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM