[英]Error: Method invocation is not a constant expression
錯誤:方法調用不是常量表達式。 顏色:Colors.black.withOpacity(0.6),當我嘗試運行這個時出現這個錯誤:
body: ListView.builder(
itemCount: 15,
itemBuilder: (context, i) => const ListTile(
title: Text("Bitcoin",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
)),
subtitle: Text("\$20000",
style: TextStyle(
color: Colors.grey.withOpacity(0.6), //error in this line
fontWeight: FontWeight.w700,
fontSize: 14,
)),
),
),
請幫助解決這個問題
您需要刪除 ListTile 之前的常量,因為 Colors.grey.withOpacity(0.6) 不是常量值。
body: ListView.builder(
itemCount: 15,
itemBuilder: (context, i) => ListTile(
title: const Text("Bitcoin",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 24,
)),
subtitle: Text("\$20000",
style: TextStyle(
color: Colors.grey.withOpacity(0.6), //error in this line
fontWeight: FontWeight.w700,
fontSize: 14,
)),
),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.