Home > Mobile >  Do I need to update the sdk version in pubspec.yaml file after upgrade flutter?
Do I need to update the sdk version in pubspec.yaml file after upgrade flutter?

Time:06-17

Do I need to update the sdk version in pubspec.yaml file after upgrade flutter? In this case do I need to change <3.0.0 to <3.1.0?

Here is my current version

environment:
  sdk: ">=2.12.0 <3.0.0"

Flutter 3.1.0-0.0.pre.1266 • channel master • https://github.com/flutter/flutter.git Framework • revision e1d9adf483 (9 hours ago) • 2022-06-15 21:56:04 -0700 Engine • revision f8c0dc87bc Tools • Dart 2.18.0 (build 2.18.0-189.0.dev) • DevTools 2.14.0

CodePudding user response:

TL;DR:

No that is not necessary, the sdk parameter refers to the version of the Dart SDK being used.

Full explanation:

The sdk refers to the version of the Dart SDK that is being used by Flutter. The Dart version used by Flutter 3.1.0-0.0.pre.1266 (current master channel) is 2.18.0 which falls perfectly into the specified range (sdk: ">=2.12.0 <3.0.0"). So in this case there is no need to update the version in your pubspec.yaml.

It might be useful to understand that a Flutter application is in fact a Dart application with a dependency on the flutter package. Therefore you'll notice that your pubspec.yaml file contains a dependency called flutter. This might look something like:

name: my_app
description: A simple Flutter App.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
  sdk: ">=2.12.0-0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

This dependency means that Dart will look for the Flutter package that is currently installed / active on the development machine and will use that to build and run your Flutter app.

If you want to ensure the Flutter application is build using a specific Flutter version (or specific range), you could update the dependency to specify a certain version:

dependencies:
  flutter: ">=3.0.0 <3.1.0"

In this example we limit the Flutter version to any version greater or equal to 3.0.0 but smaller than 3.1.0. This is however not recommended as everybody that would like to build your application can only do so if they have that specific version of Flutter installed and active on their machine.

CodePudding user response:

Yes you should upgrade the sdk version in pubspec if you upgraded the flutter version of your system, but if you don't want to update the pubspec yaml and want to code into the legacy/old code of it flutter has its own flutter version management

link : https://fvm.app/

CodePudding user response:

No,after you upgrade flutter,the sdk version in pubspec.yaml for the existing projects won't change automatically.If you want it to latest then you have to change it manually.For new projects that you are creating after upgrading flutter it will take the latest version automatically.

  • Related