'The library 'package:flutter/material.dart' is legacy, and should not be imported into a null safe library
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?
Solution 1:[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:[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:[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:[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
Solution 5:[5]
I was facing the same problem with the Adhan Dart package, when i read the documentation on the package site , i had the Prereleased version so i made changes to the dependences as adhan: ^2.0.0-nullsafety.2 and it worked.
For more details:https://pub.dev/packages/adhan/versions/2.0.0-nullsafety.1
Solution 6:[6]
go to https://pub.dev/packages/font_awesome_flutter,
copy the latest release version of font i.e in my case (font_awesome_flutter: ^9.1.0),
then add it to your pubspec.yaml file i.e (font_awesome_flutter: ^9.1.0),
click pub get dependencies
go to your input_page file
click get dependencies
Solution 7:[7]
Copy the latest version of the package which is giving the error from http://pub.dev/ and paste it in the pubspec.yaml file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Yash Mathur |
| Solution 2 | Susanta Kumar Behera |
| Solution 3 | Felipe Sales |
| Solution 4 | Mohan Kumar N |
| Solution 5 | KhuzaimaA |
| Solution 6 | Ian Brian Trevor Kibet |
| Solution 7 | Mahwish - |

