I have been playing around with some flutter basics on Windows then wanted to test it on Mac. I did successfully but when I got back again to windows to work on it again I found out that VSCode changed Flutter SDK path in the whole project. The Flutter SDK path on windows is
C:\Users\USERNAME\Documents\sdk\flutter
And on Mac
/Users/USERNAME/Downloads/flutter
When I tried to test it again on Windows after Mac I got so many errors like this
Error: Error when reading '/Users/USERNAME/Downloads/flutter/packages/flutter/lib/material.dart': The system cannot find the path specified.
I run flutter doctor
and got this
When I searched for the path of Flutter SDK on Mac in the project I found this
I searched for dart.flutterSdkPath
in the settings and changed the path but that didn't fix this issue
"dart.flutterSdkPath": "C:/Users/USERNAME/Documents/sdk/flutter"
so I had to use search and replace tool to replace the path of Mac to the path of Windows in all of these files. It worked but how can I prevent changing the SDK path in the project every time I switch between Windows and Mac?
All those file that you mentioned should be ignored already on the .gitignore
created by the flutter create command. It will be generated automatically when you build your project.
In case you don't have it, here is the default .gitignore
file
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
# IntelliJ related
*.iml
*.ipr
*.iws
.idea/
# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/
# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/
# Web related
lib/generated_plugin_registrant.dart
# Symbolication related
app.*.symbols
# Obfuscation related
app.*.map.json
# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
After changing the .gitignore
files, make sure to run git rm -r --cached.
before git add.
to ensure Git is tracking the right files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.