Last Updated on 2021-10-15 by Clay
這是由於 dart 版本升級之後的程式碼,有部分需要啟用所謂的『空安全』(Null-Safety)才能正常編譯所導致的。
你應該會看見下列訊息:
This requires the 'non-nullable' language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.12.0 or higher, and running 'pub get'.
解決方法:啟用 Null-Safety
1. 確認你的 Dart 版本(以我的例子,需要至少為 2.12)。
dart --version
如版本過低,需要升級至所需的最低版本。
2. 使用以下指令確認你項目中的函式庫、套件是否需要升級到 Null-Safety
dart pub upgrade --null-safety
dart pub get
dart pub outdated --mode=null-safety
3. 遷移(若有報錯,則代表有函式庫、套件不支援 Null-Safety)
dart pub outdated --mode=null-safety
References
- https://stackoverflow.com/questions/64621051/how-to-enable-null-safety-in-flutter
- https://github.com/flutter/flutter/issues/62414
- https://dart.dev/null-safety/migration-guide
Read More
- [已解決][Flutter] Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera]
- [已解決] Error: This requires the null safety language feature, which is experimental. You can enable the experiment using the '--enable-experiment=non-nullable' command line option.