preface

Google’s launch of Flutter, a new high-performance cross-platform (Android, ios) rapid development framework, has attracted the attention of many developers in the industry. After I touched Flutter, I realized that this is really a good thing. Good things have to be shared, right?

Today I’m going to share with you how to resolve dependencies on Flutter.

This article originally appeared on: Iiro’s blog.

Why do version dependencies exist

We often rely on third-party libraries when developing flutter projects. The more dependencies a FLUTTER has, the more likely it is that there will be dependency version conflicts.

Because new_trend depends on build_runner >=0.9.0 whichRequires SDK version >=2.0.0-dev.61 <3.0.0, version solving failed. Pub get failed (1)Copy the code

Its pubspec.yaml file should look something like this

dev_dependencies:
  build_runner: ^0.9. 0
Copy the code

It is clear from the error message that this is due to a build_Runner and SDK version conflict.

The solution

When it is not clear which version of a dependency should be used at the moment, we can use any to resolve version-dependent version conflicts.

dev_dependencies:
  build_runner: any
Copy the code

Any automatically calls pub’s version analyzer to find the appropriate conflict-avoiding dependencies and download them. We will no longer see pub complaining about version-dependent version conflicts.

Yet!!!

We know we shouldn’t leave any there, so we need to replace the any keyword with the correct dependency version!

Use Pubspec.lock to find the correct version

We open Pubspec.lock, which is a file generated based on the current project dependencies and records the version of the dependencies currently in use.

Go back to the pubspec.yaml file and replace the any version number with the actual version.

dev_dependencies:
  build_runner: 0.83.
Copy the code

This is the perfect way to solve the version dependency problem

Q&A:

Why not just use any as the version number

In real project development, having an uncertain version number is a huge risk for future application crashes. This can make your application difficult to debug. So remember, don’t leave the any keyword in your project!

Write in the last

If you have any other problems with the Flutter project regarding version dependencies, please leave them in the comments section below or send me an email at [email protected] and I’ll be happy to answer your questions!