跳至主要內容

provide_deprecation_message

穩定版
核心

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

詳細資訊

#

務必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

如果您改用 YAML 地圖語法來設定 linter 規則,請在 linter > rules 下新增 provide_deprecation_message: true

analysis_options.yaml
yaml
linter:
  rules:
    provide_deprecation_message: true