简体   繁体   中英

Dart null safety - How to disable null safety analysis for certain file?

The problem:

some of pub packages doesn't support null safety yet.

For example intl_translation cannot parse a file with null safety operators and throw Errors as below if any of symbols (as?, . etc) found.

Invalid argument(s): Parsing errors in lib/localizations/MainLocalizations.dart
#0      MessageExtraction._parseCompilationUnit (package:intl_translation/extract_messages.dart:117:7)
#1      MessageExtraction.parseContent (package:intl_translation/extract_messages.dart:102:14)
#2      MessageExtraction.parseFile (package:intl_translation/extract_messages.dart:87:12)
#3      main (file:///.../flutter/.pub-cache/hosted/pub.dartlang.org/intl_translation-0.17.10+1/bin/extract_to_arb.dart:98:31)
#4      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Then it generates dart files which are not using null safety too and it causes numerous errors during $ flutter run .

So is there a way to disable warnings or null safety for at least success compilation? because $ flutter run --no-sound-null-safety doesn't helps:(

Thank you for any help!

You can disable it per library. This requires to add special comment at the beginning of file.
Example.

// @dart=2.10
import 'foo.dart';

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