The library 'package:flutter/material.dart' is legacy, and should not be imported into a null safe library

36,381

Solution 1

The fix for this is relatively simple. Just go to your pubspec.yaml file and make sure the lottie dependancy that you have there, is the latest version as on the pub.dev site.

Solution 2

Use dart pub outdated --mode=null-safety and then dart pub upgrade --null-safety to upgrade all your dependencies to null-safety.

For more details go to https://dart.dev/null-safety/migration-guide.

Solution 3

Currently, on 8/29/2021, auto_size_text package also keeps giving this alert, because I was using the Null Safety versions of Dart - 2.12.0, and to solve this, I looked in the package documentation and saw that I had a Prerelease version to Null Safety - launch, so I used it.

dependencies:
  auto_size_text: ^3.0.0-nullsafety.0

Solution 4

[![The library 'package:flutter_/.dart' is legacy, and should not be imported into a null safe library. Try migrating the imported library.

Open run/debug option -> select edit configuration as shown in image one.]1]1

And then add in --no-sound-null-safety in Additional run args section ->Apply->ok->run appllication it works for me.imgur.com/A9aEb.png

Share:
36,381
Suragch
Author by

Suragch

Read my story here: Programming was my god

Updated on August 30, 2021

Comments

  • Suragch
    Suragch almost 3 years

    I have a null-safe library and in the example folder I'm using the following import:

    import 'package:flutter/material.dart';
    

    However, the linter is giving me the following warning:

    The library 'package:flutter/material.dart' is legacy, and should not be imported into a null safe library. Try migrating the imported library. import_of_legacy_library_into_null_safe

    The example project's pubspec.yaml file specifies the beta version of the Dart SDK:

    environment:
      sdk: ">=2.12.0-29.10.beta <3.0.0"
    
    dependencies:
      flutter:
        sdk: flutter
      my_library:
        path: ../
    

    Hasn't material.dart already been converted by now? Do I need to add something else to pubspec.yaml or just wait for the stable release to come out?

  • DragoRaptor
    DragoRaptor almost 3 years
    Just upgraded the faulty packages and it resolved the issue. Thanks bud upvoting your answer. :-)
  • Mohan Kumar N
    Mohan Kumar N almost 3 years
    Add --no-sound-null-safety this in editconfigaration it works
  • Banani720
    Banani720 about 2 years
    Why has this not been marked as the correct answer, literally a tool offered by Dart to resolve one of the most commonly faced Dart issues