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

how to resolve this error of null safe library in splash screen even though I have added dependency most recent one i.e "splashscreen: ^1.3.5"

To import a package without null safety support reduce your flutter version in pubspec.yaml
Replace environment with bellow version
environment:
sdk: ">=2.06.0 <3.0.0"
Note: This is one way to use an external package without null safety support. If it's an existing project check your dependencies for null safety support before migrating.

Related

Null safety migration error: package has unmigrated dependencies. But all my dependencies declare support for null-safety

Im trying to migrate dart null safety but I get the following error when I run dart migrate
Bad state: Error: package has unmigrated dependencies.
Before migrating your package, we recommend ensuring that every library it
imports (either directly or indirectly) has been migrated to null safety, so
that you will be able to run your unit tests in sound null checking mode. You
are currently importing the following non-null-safe libraries:
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/basic_project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/deferred_components_config.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_driver.dart
file:///C:/flutter/packages/flutter_tools/test/src/test_flutter_command_runner.dart
file:///C:/flutter/packages/flutter_tools/test/src/testbed.dart
package:dwds/data/build_result.dart
package:dwds/data/connect_request.dart
package:dwds/data/debug_event.dart
package:dwds/data/devtools_request.dart
package:dwds/data/error_response.dart
package:dwds/data/extension_request.dart
package:dwds/data/isolate_events.dart
package:dwds/data/register_event.dart
package:dwds/src/debugging/dart_scope.dart
package:dwds/src/debugging/debugger.dart
package:dwds/src/debugging/execution_context.dart
package:dwds/src/debugging/frame_computer.dart
package:dwds/src/debugging/inspector.dart
package:dwds/src/debugging/instance.dart
package:dwds/src/debugging/libraries.dart
package:dwds/src/debugging/location.dart
package:dwds/src/debugging/metadata/class.dart
package:dwds/src/debugging/metadata/function.dart
package:dwds/src/debugging/metadata/module_metadata.dart
package:dwds/src/debugging/metadata/provider.dart
Please upgrade the packages containing these libraries to null safe versions
before continuing. To see what null safe package versions are available, run
the following command: `dart pub outdated --mode=null-safety`.
When I run dart pub outdated --mode=null-safety I got this message and everything seems to be ready for null safety:
C:\flutter\packages\flutter_tools>flutter pub outdated --mode=null-safety
Showing dependencies that are currently not opted in to null-safety.
[✗] indicates versions without null safety support.
[✓] indicates versions opting in to null safety.
All your dependencies declare support for null-safety.
How can I upgrade these packages and migrate to null safety? Appreciate every answer :)
You can use migration helper tool with this command line:
dart migrate
Or you can migrate manually after change min flutter sdk version in pubspec.yaml
environment:
sdk: '>=2.12.0 <3.0.0'
and after this change you need launch this command:
flutter pub get
The tool is listing the following files as non-null-safe:
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/basic_project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/deferred_components_config.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_data/project.dart
file:///C:/flutter/packages/flutter_tools/test/integration.shard/test_driver.dart
file:///C:/flutter/packages/flutter_tools/test/src/test_flutter_command_runner.dart
file:///C:/flutter/packages/flutter_tools/test/src/testbed.dart
They belong to Flutter itself:
https://github.com/flutter/flutter/tree/master/packages/flutter_tools/test
So you should update Flutter itself. You can do this in pubspec.yaml:
environment:
sdk: ">=2.15.0 <3.0.0"
flutter: ">=2.10.0" # <= here
I am not sure which version got those files migrated, so try the most recent one that does not break your code too much.
That is because you need update your packages, some packages don't have support for null safety , then you need to check each one of your packages ,
for example.. you can looking some package and on the top say if the package have or not have support for null safety (for example the image ), (sometimes users update in other repositories then check on the issues page from GitHub *if the package don't have support)

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

I am trying to use a vin decoder package in my app. When I import the package:
import 'package:vin_decoder/vin_decoder.dart';
but I am getting this warning:
The library 'package:vin_decoder/vin_decoder.dart' is legacy, and should not be imported into a null safe library.
Try migrating the imported library.
My pubspec.yaml has this under dependencies:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
vin_decoder: ^0.1.4
Can someone explain what I am doing wrong? I checked out this stack overflow question but nothing worked.
Thank you.
You are doing nothing wrong. Currently this package has not released a null safety version yet, and you project is null safe. Check package, there is a prerelease version 0.2.1-nullsafety. Either wait for it to be released, or use this prerelease version, but of course it can contain bugs.

Unsound null safety without upgrading legacy packages

My app has a lot of legacy library (e.g. EPUB, EPUB_KITTY) which does not support Null Safety yet and the authors are already inactive.
I've read that we can mix non null safe library and null safe library by adding // #dart=2.9 at the main or adding
--no-sound-null-safety during build.
So first I've updated my sdk in pubspec.yaml into:
environment:
sdk: ">=2.12.0 <3.0.0"
then I've also updated all of the dart files to support null safety.
and the build command I ran is:
flutter run --no-sound-null-safety
But i've encountered errors with path_provider: ^1.6.11:
../../flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.4+1/lib/src/path_provider_windows_real.dart:126:25: Error: The getter 'addressOf' isn't defined for the class 'GUID'.
- 'GUID' is from 'package:win32/src/structs.dart' ('../../flutter/.pub-cache/hosted/pub.dartlang.org/win32-1.7.3/lib/src/structs.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'addressOf'.
knownFolderID.addressOf, KF_FLAG_DEFAULT, NULL, pathPtrPtr);
^^^^^^^^^
I thought this is because of null safety but it should not show that error right? since I was using the --no-sound-null-safety command? Anyways, I've upgraded the path_provider into path_provider: ^2.0.2 (latest null safety version) to see if it would fix the problem but after building I've encountered another problem about dependency incompatibility, so I've updated the old packages again to fix the incompatibility problem but eventually I've reached the point where the error is about the EPUB package as describe below:
Because image >=3.0.1 depends on xml ^5.0.0 and epub >=1.3.0 depends on xml >=2.6.0 <4.0.0, image >=3.0.1 is incompatible with epub >=1.3.0.
So, because testco depends on both epub ^2.0.0 and image ^3.0.2, version solving failed.
What should I do about this? The author of this package is already inactive so should I fork the epub package and update the xml library version manually to fix the build error? or is there a way to solve this without updating the epub package internals? Please advise.
Thanks!
When you look at the package, you will see that there is an issue opened about null-safety.
While the author has not replied and seems inactive for years, people have forked it and this fork was updated to null-safety.
https://pub.dev/packages/epubx
You have to test whether this meets your needs. If it doesn't, consider helping them or forking it on your own.
The same goes for every other package. Check their issues page, see if other people had the same problem and maybe it was fixed or they fixed it on their own. If there is no issue about null-safety, you should maybe look for a different package alltogether, because that means nobody is using it but you.

How to disable Flutter sound-safety and null-safety for the SplashScreen library?

I am trying to run the SplashScreen library but it isn't working.
I have edited the package’s pubspec.yaml file, setting the minimum SDK constraint to 2.7.0,
It brought out this error:
lib/mySplashScreen.dart:5:28: Error: Null safety features are disabled
for this library. Try removing the package language version or setting
the language version to 2.12 or higher. const MySplashScreen({Key?
key}) : super(key: key);
^ Error: Cannot run with sound null safety, because the following dependencies don't support null safety:
package:ar_app
package:splashscreen For solutions, see https://dart.dev/go/unsound-null-safety
I added a language version comment to the top of the Dart files, ie: // #dart=2.9
It brought this error:
Error: A library can't opt out of null safety by default, when using
sound null safety. // #dart=2.9 ^^^^^^^^^^^^
What do I do?
If you want you can just disable null safety, without downgrading.
Add this to your launch configuration:
--no-sound-null-safety
More info on https://dart.dev/null-safety/unsound-null-safety
it saying you can not user a non null safe package while using Dart null safety or sound null safety
Now you have one option to keep using non null safe package. that is you have to downgrade your flutter to non null safe version
to achieve that run the following command
flutter pub downgrade
To disable null safety change flutter SDK version to:
environment:
sdk: ">=2.11.0 <3.0.0"
in pubspec.yaml file

Flutter null safety checks

flutter seems to be switching between null safety checks and nonnull safety checks causing dozens of issues.
Running: flutter clean remove all null check errors,
but when I run: flutter pub get the null errors return?
Really confusing, my dart sdk:
environment:sdk: ">=2.11.6 <3.0.0"
I think dart was updated recently to include null checks and it seems to be causing loads of problems for me, I have corrected the null errors before anyone suggests this and when I run flutter clean the null error check I have implemented cause errors.
lib/screens/add_new_location_note_screen.dart:23:8:
Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher. Place? _pickedLocation;
Now I have changed the minimum sdk to
environment: sdk: ">=2.12.0 <3.0.0"
ran: flutter clean
and the errors again disappear now running: flutter pub get
the null errors checks return ???
You must set the SDK constraints like so:
environment: sdk: ">=2.12.0-0 <3.0.0"
Currently, the 2.12 SDK is in pre-release (beta), requiring the use of the -0 to signify the pre-release version to use.