目錄

provide_deprecation_message

透過 @Deprecated("訊息") 提供棄用訊息。

此規則從 Dart 2.2 開始提供。

規則集:核心建議flutter

詳細資料

#

請務必Deprecated 建構子中指定棄用訊息(包含遷移指示和/或移除時程)。

錯誤

dart
@deprecated
void oldFunction(arg1, arg2) {}

正確

dart
@Deprecated("""
[oldFunction] is being deprecated in favor of [newFunction] (with slightly
different parameters; see [newFunction] for more information). [oldFunction]
will be removed on or after the 4.0.0 release.
""")
void oldFunction(arg1, arg2) {}

用法

#

若要啟用 provide_deprecation_message 規則,請在您的 analysis_options.yaml 檔案中的 linter > rules 下新增 provide_deprecation_message

analysis_options.yaml
yaml
linter:
  rules:
    - provide_deprecation_message