You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter容器内文本颜色修改报错:无‘color’命名参数问题解决

容器加色后修改文本颜色的错误解决办法

为啥报错?

你这段出错的代码里,把color: Colors.white直接放在了Text组件的参数里,但Text根本没这个参数!文本颜色得通过style里的TextStyle来设置才行。

错误代码片段:

Text("Inserieren",
style: TextStyle(fontSize: 50.0),color: Colors.white),

怎么改?

把color: Colors.white挪到TextStyle的括号里就行,修复后的代码:

Text("Inserieren",
style: TextStyle(fontSize: 50.0, color: Colors.white)),

对应你代码里的容器部分,修复后完整片段

Container(
  color: Colors.grey[900],
  child: Row(
    children: const [
      SizedBox(width: 40),
      Text("Inserieren", style: TextStyle(fontSize: 50.0, color: Colors.white)),
    ],
  ),
),

额外提醒

Flutter里所有文本的样式(颜色、字号、粗细这些),都得通过Text的style属性传TextStyle对象来配置,不能直接给Text塞样式参数。你顶部导航栏里的文本写法是对的,照着那个来就没问题。

内容的提问来源于stack exchange,提问作者user19877113

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 04:40:24