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

3,033

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

// @dart=2.10
import 'foo.dart';
Share:
3,033
Arenukvern
Author by

Arenukvern

Updated on December 27, 2022

Comments

  • Arenukvern
    Arenukvern over 1 year

    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!

  • Arenukvern
    Arenukvern about 3 years
    Tested, exactly what is needed, thank you very much! It switched whole file to specified language version, not just library:)
  • Machisuji
    Machisuji about 3 years
    Is there a way to just get the library in that version but have the rest of the file remain the current version?
  • MubarakZade
    MubarakZade almost 3 years
    This worked perfectly for Android. Thank you. But still, I'm not able to run in iOS. Facing errors.