簡體   English   中英

錯誤:可選參數的默認值必須是常量

[英]Error: The default value of an optional parameter must be constant

將默認值分配給 Color 類型的實例變量時出現錯誤。 僅當我為 colors 分配陰影值時,我才會收到此錯誤。

錯誤:可選參數的默認值必須是常量。

class CardPanelHeader extends StatelessWidget {
  final String leadingPanelText;
  final Color leadingPanelTextColor;
  final String trailingPanelText;
  final Color trailingPanelTextColor;

  const CardPanelHeader({
    Key key,
    this.leadingPanelText,
    this.leadingPanelTextColor = Colors.black87,
    this.trailingPanelText,
    this.trailingPanelTextColor = Colors.grey.shade600,
  }) : super(key: key);

我確實檢查了這個解決方案,但對我沒有用。

誰能幫我解決這個問題。 提前致謝!

您可以使用顏色的絕對值作為常數值; Colors.grey.shade600更改為const Color(0xFF757575)您可以找到 colors https://material.io/resources/color/的十六進制代碼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM