Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 832
Arenukvern Avatar asked Dec 22 '22 16:12

Arenukvern


1 Answers

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

// @dart=2.10
import 'foo.dart';
like image 129
mezoni Avatar answered May 12 '23 13:05

mezoni