Skip to content

[已解決][Flutter] 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’.

這是由於 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


Read More

Tags:

Leave a Reply