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?
Use the null assertion operator ( ! ) to make Dart treat a nullable expression as non-nullable if you're certain it isn't null. is null, and it is safe to assign it to a non-nullable variable i.e.
What is null safety in Flutter? Flutter null safety is the feature that became available after the release of version 2 where the minimum version of Dart programming language is set to 2.12. This feature helps to improve developers' productivity by eliminating a whole class of bugs caused by null dereferencing errors.
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.
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.
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
[![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
.imgur.com/A9aEb.png
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With