Reputation: 512296
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?
Upvotes: 36
Views: 61466
Reputation: 31
in my case my firebase_core package was not of the latest version. do check yours or any other firebase related dependencies. some packages maybe old version.
Upvotes: 2
Reputation: 331
In case someone comes here looking for this error because of the flutter realm package.
Please change your realm version in your pubspec.yaml
file to a version with null safety. Check out the latest realm versions from https://pub.dev/packages/realm/versions.
Change From
dependencies
realm: ^0.0.1
To
dependencies
realm: ^0.8.0+rc //check for latest version
Upvotes: 2
Reputation: 887
In my case I got this error because I defined 'firebase_core' dependency in the pubspec.yaml file under the 'dev_dependencies' but it was wrong.
I've done 3 easy steps to solve the issue as following:
1- I've got the latest version from https://pub.dev/packages website.
2- I've defined the packages under 'dependencies' in the pubspec.yaml file as following:
dependencies:
flutter:
sdk: flutter
firebase_core: ^2.3.0
3- I've imported the package in the main.dart file as following:
import 'package:firebase_core/firebase_core.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
Upvotes: 0
Reputation: 51
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
Upvotes: 1
Reputation: 1149
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
Upvotes: 2
Reputation: 9
Copy the latest version of the package which is giving the error from http://pub.dev/ and paste it in the pubspec.yaml file.
Upvotes: 0
Reputation: 501
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.
Upvotes: 40
Reputation: 11
[![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
Upvotes: 1
Reputation: 1
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
Upvotes: 0
Reputation: 243
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.
Upvotes: 21