Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 834
Suragch Avatar asked Jan 29 '21 05:01

Suragch


People also ask

How do you handle null safety in darts?

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 package?

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.


Video Answer


5 Answers

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.

like image 95
Yash Mathur Avatar answered Oct 19 '22 02:10

Yash Mathur


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.

like image 32
Susanta Kumar Behera Avatar answered Oct 19 '22 02:10

Susanta Kumar Behera


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
like image 2
Felipe Sales Avatar answered Oct 19 '22 02:10

Felipe Sales


[![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

like image 1
Mohan Kumar N Avatar answered Oct 19 '22 04:10

Mohan Kumar N


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

like image 1
KhuzaimaA Avatar answered Oct 19 '22 02:10

KhuzaimaA