|

|  Cannot run with sound null safety, because the following dependencies don't support null safety in Flutter: Causes and How to Fix

Cannot run with sound null safety, because the following dependencies don't support null safety in Flutter: Causes and How to Fix

February 10, 2025

Discover causes and fixes for sound null safety issues in Flutter. Learn which dependencies lack support and how to resolve these to ensure smooth app development.

What is Cannot run with sound null safety, because the following dependencies don't support null safety Error in Flutter

 

Understanding the Error Message

 

  • Flutter's switch to sound null safety enhances code reliability by enforcing non-nullability checks. This error occurs when certain dependencies in your Flutter project aren't compatible with this feature.
  •  

  • The absence of null safety support in any dependency means the application cannot guarantee that variables aren't assigned null values unless explicitly allowed, leading to runtime errors.
  •  

 

Functionality of Null Safety

 

  • Null safety helps catch null dereferencing issues during the development stage, avoiding potential runtime crashes.
  •  

  • It introduces non-nullable types, promoting more robust and predictable code.
  •  

 

Implications of Using Non-Compatible Dependencies

 

  • Without null safety, the development workflow might face unpredictable outcomes, as the Dart analyzer cannot ensure null checks at compile time.
  •  

  • This could lead to increased technical debt, where temporary workarounds for non-migrated packages could complicate the project's future scalability and maintenance.
  •  

 

Impact on the Development Environment

 

  • Projects using non-null safe dependencies might need additional testing and debugging efforts to catch null reference errors.
  •  

  • Such dependencies may force the use of legacy code paths or prevent leveraging the full capabilities of newer Dart/Flutter updates, slowing down feature implementation.
  •  

 

Consideration for Future Updates

 

  • Developers must keep an eye on package updates, as package maintainers frequently roll out null safety compatibility updates.
  •  

  • Preferring dependencies with active support and updates can ease the transition to null safety.
  •  

 

What Causes Cannot run with sound null safety, because the following dependencies don't support null safety in Flutter

 

Cause of 'Cannot run with sound null safety' Error

 

  • This error typically occurs because some dependencies in the Flutter project do not support sound null safety. Null safety is a feature introduced in Dart to help control nullable and non-nullable types, thus improving code quality and reducing runtime errors. If a package has not been updated to include null safety, it can cause conflicts when attempting to run a Flutter project in a null-safe environment.
  •  

  • Some older packages or libraries might not have been maintained or upgraded to support null safety, causing projects using those dependencies to fail when running in a null-safe environment.
  •  

  • Mixing null-safe enabled and non-null-safe libraries within a project leads to this issue. This happens because when the Flutter application attempts to enable sound null safety, it requires that all the dependencies also support null safety.

 

Dependency Version Constraints

 

  • If the version constraints in the `pubspec.yaml` file are set to outdated versions of the dependencies, it could inadvertently enforce using versions of libraries that are not null-safe. It is essential to ensure that the constraints are set to versions that include null safety, albeit such measures might require manual adjustments.
  •  

  • Another cause of this issue might be transitive dependencies, where a package used by a dependency within the project does not support null safety, even if the direct dependency does. This can be seen when an updated package depends on another package that has yet to adopt null safety.

 

Example of Dependency Declaration

 

dependencies:
  flutter:
    sdk: flutter
  some_nullable_package: ^0.1.2

 

  • Here, `some_nullable_package` might not have null safety, indicated by a version that predates a null-safe update. This would cause an error when attempting to run with sound null safety.

 

Project Downgrade

 

  • Sometimes, the Flutter SDK itself or Dart SDK might be in a version that assumes non-null-safe libraries by default. While this is uncommon, particularly if the SDK is not updated regularly, it can lead to conflicts and the error message in question.
  •  

  • Similarly, to save time and resources, developers might intentionally use older versions of the SDK to maintain compatibility with various tools or plugins, resulting in constraints against null safety utilization.

 

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi Dev Kit 2.

How to Fix Cannot run with sound null safety, because the following dependencies don't support null safety in Flutter

 

Identify Non-Compliant Dependencies

 

  • Check your `pubspec.yaml` file for the list of dependencies with lower versions that do not support null safety.
  •  

  • Run the following command to get detailed information about dependencies that don’t support null safety:

 


dart pub outdated --mode=null-safety

 

Upgrade Dependencies

 

  • Update your dependencies in the `pubspec.yaml` to the latest versions that support null safety. Use the command below to help update packages to the newest compatible versions:

 


dart pub upgrade --nullsafety

 

  • If certain packages do not have a null-safe version, check if there are alternatives or consider contributing to the package's development to enhance support.

 

Add Temporary Overrides

 

  • For dependencies that are not yet null safe, consider using `dependency_overrides` in your `pubspec.yaml`. This can force the use of a newer version of a package or a fork that supports null safety. Here’s how you can override:

 


dependency_overrides:
  some_package:
    git:
      url: https://github.com/username/some_package
      ref: null-safety

 

  • Ensure the overridden package is stable for production use.

 

Use Migration Tools

 

  • If you maintain the package or want to contribute to its migration, utilize Dart’s migration tool. First, activate the migration tool:

 


dart pub global activate dart_migrate

 

  • Then, navigate to the package directory and run the migration command:

 


dart migrate

 

  • Follow the tool’s guide to apply the suggested changes and test thoroughly.

 

Contact Maintainers

 

  • If a dependency is crucial and lacks support, contact the package maintainers through their repository issue tracker or contact information, requesting an update.

 

Downgrade Flutter/Dart SDK

 

  • As a last resort, consider downgrading to a Flutter or Dart SDK version that doesn’t enforce null safety, but note this isn’t ideal for long-term projects:

 


flutter version v1.x.x

 

  • This can be done using the Flutter version manager (`fvm`) to switch between SDK versions as needed.

 

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

Order Friend Dev Kit

Open-source AI wearable
Build using the power of recall

Order Now

Join the #1 open-source AI wearable community

Build faster and better with 3900+ community members on Omi Discord

Participate in hackathons to expand the Omi platform and win prizes

Participate in hackathons to expand the Omi platform and win prizes

Get cash bounties, free Omi devices and priority access by taking part in community activities

Join our Discord → 

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded

OMI NECKLACE: DEV KIT
Order your Omi Dev Kit 2 now and create your use cases

Omi Dev Kit 2

Endless customization

OMI DEV KIT 2

$69.99

Speak, Transcribe, Summarize conversations with an omi AI necklace. It gives you action items, personalized feedback and becomes your second brain to discuss your thoughts and feelings. Available on iOS and Android.

  • Real-time conversation transcription and processing.
  • Action items, summaries and memories
  • Thousands of community apps to make use of your Omi Persona and conversations.

Learn more

Omi Dev Kit 2: build at a new level

Key Specs

OMI DEV KIT

OMI DEV KIT 2

Microphone

Yes

Yes

Battery

4 days (250mAH)

2 days (250mAH)

On-board memory (works without phone)

No

Yes

Speaker

No

Yes

Programmable button

No

Yes

Estimated Delivery 

-

1 week

What people say

“Helping with MEMORY,

COMMUNICATION

with business/life partner,

capturing IDEAS, and solving for

a hearing CHALLENGE."

Nathan Sudds

“I wish I had this device

last summer

to RECORD

A CONVERSATION."

Chris Y.

“Fixed my ADHD and

helped me stay

organized."

David Nigh

OMI NECKLACE: DEV KIT
Take your brain to the next level

LATEST NEWS
Follow and be first in the know

Latest news
FOLLOW AND BE FIRST IN THE KNOW

thought to action.

team@basedhardware.com

Company

Careers

Invest

Privacy

Events

Vision

Trust

Products

Omi

Omi Apps

Omi Dev Kit 2

omiGPT

Personas

Resources

Apps

Bounties

Affiliate

Docs

GitHub

Help Center

Feedback

Enterprise

© 2025 Based Hardware. All rights reserved.