Running old code on new flutter and dart version

Viewed 208

I abandoned a project I was working on for a while I came back to open it on upgraded flutter and dart plugin in visual studio code windows 10.now I get so many problems. is there a way to automatically update code to solve these errors?

2 Answers

do these steps:

  1. delete build folder
  2. delete .idea folder
  3. run flutter clean
  4. run flutter pub get
  5. run flutter pub upgrade

then try to run your project.

The simple answer is it depends.

Judging by the comments from a reasonably good answer by Hasan Abbasi, this wasn't enough. Depending on how old your project is, there are 2 choices before or after doing what that answer said:

  1. If it's any more than 2 or 3 years old, I'd probably rewrite it from scratch. In that time, Flutter and Dart have matured greatly, which involves many breaking changes. Also, null-safety has been introduced. Creating a new project after updating Flutter will also fix those Gradle issues because the configuration files will be reset.
  2. If it's less than that, try to fix those Gradle issues either by hand or just deleting the '/android' or '/ios' etc. folders and letting Flutter/Dart automatically recreate them when you run the app next. You'll probably need to migrate to null-safety: read about null-safety so you understand it properly, then try using the dart migrate tool. You will likely need to spend some time changing dependencies for null-safe versions. Then you can try the flutter fix tool to automatically resolve SOME issues.

Hope you can get your app to work soon!

Related