Search code examples
flutterdartsdkflutter-dependencies

How do I know which Flutter version to use for an existing project?


I just cloned a repository of a Flutter project and I don't know which flutter sdk version should I use. I tried with 5-6 version and every one of them threw an error (errors like "this function doesn't exist" or something like that.

I use the version 3.18.0-0.1.pre (since it says that in the pubspec.lock at the end, and with that version I was able to run the project, but I had to change the version of the package intl since it threw an error saying this:

Note: intl is pinned to version 0.18.1 by flutter_localizations from the flutter SDK.
See https://dart.dev/go/sdk-version-pinning for details.
2

Because every version of flutter_localizations from sdk depends on intl 0.18.1 and evita_mobile depends on intl ^0.19.0, flutter_localizations from sdk is forbidden.
So, because evita_mobile depends on flutter_localizations from sdk, version solving failed.

I was able to run the project, but it doesn't work like it should (I wasn't able to get past the login page, since the functions to authenticate the user don't work). I think this is because it changed a lot of things in the pubspec.lock

At the moment, I don't know if the problem is the version of Flutter, but this is my theory, since the previous programmer who left the company was able to run the project without problems.

I already tried a lot of terminal codes like flutter pub get, flutter pub outdated, flutter pub upgrade, flutter pub upgrade --major-versions and so more.

I will drop the pubspec.yaml here because I think it's important:

name: evita_mobile
description: A new Flutter project.

version: 1.0.0+1

environment:
  sdk: ">=2.19.2 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2
  http: ^0.13.4
  shared_preferences: ^2.0.15
  intl: ^0.19.0
  flutter_html: ^3.0.0-alpha.6
  encrypt: ^5.0.1
  file_picker: ^5.2.6
  mime: ^1.0.4
  path_provider: ^2.0.14
  syncfusion_flutter_pdfviewer: ^21.2.3
  flutter_barcode_scanner: ^2.0.0
  chewie_audio: ^1.5.0
  flutter_localizations:
    sdk: flutter
  dots_indicator: ^3.0.0
  font_awesome_flutter: ^10.5.0
  url_launcher: ^6.0.12
  table_calendar: ^3.0.9
  flutter_launcher_icons: ^0.13.1
  flutter_local_notifications: ^9.0.0
  permission_handler: ^10.4.5
  workmanager: ^0.5.2
  flutter_secure_storage: ^8.1.0
  flutter_inappwebview: ^5.5.0+5
  infinite_scroll_pagination: ^4.0.0

flutter_icons:
  image_path: "lib/images/evita_logo.png"
  android: true
  ios: true

dev_dependencies:
  flutter_test:
    sdk: flutter
  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true
  assets:
    - lib/images/

Solution

  • If you can open the pubspec.lock file you will be able to see the flutter and dart version at the bottom of file. There you can compare it with your's version.

    Remove dependency issues you can check for outdated packages in pubspec.yaml file or by running command in Terminal. And then run flutter pub upgrade --major-versions to upgrade the packages to latest relevant versions. It may help to sort your issue.