【发布时间】:2021-06-07 08:45:00
【问题描述】:
我正在尝试将我的 FlatButton 迁移到 TextButton。由于FlatButtons 已被弃用,因为我升级了我的颤振版本。我目前正在努力调整背景颜色。
旧按钮:
FlatButton(
height: height,
onPressed: onPressed,
shape: baseButtonBorder,
color: Colors.red,
child: Text(label, style: TextStyle(color: fontColor, fontWeight: boldLabel ? FontWeight.bold : FontWeight.normal)),
)`
新按钮:
TextButton(
onPressed: onPressed,
style: ButtonStyle(backgroundColor: Colors.red), // <-- Does not work
child: Text(label, style: TextStyle(color: fontColor, fontWeight: boldLabel ? FontWeight.bold : FontWeight.normal)),
),
扁平按钮没有color 属性,所以我尝试使用style 属性并添加ButtonStyle。飞镖怎么说:
The argument type 'MaterialColor' can't be assigned to the parameter type 'MaterialStateProperty<Color>'.
如何像以前使用FlatButton 一样将TextButton 设置为红色?我需要用红色创建MaterialStateProperty<Color>吗?
【问题讨论】:
标签: flutter