按下时更改OutlineButton的文本颜色

时间:2020-06-27 19:00:26

标签: flutter dart

我似乎并没有在大纲按钮中找到属性来突出显示或按下时更改文本颜色。

    OutlineButton(
      child: Text('Delete'),
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(4.0)),
      borderSide: BorderSide(color: Colors.redAccent),
      highlightedBorderColor: Colors.redAccent,
      highlightColor: Colors.redAccent,
      textColor: Colors.redAccent,
      onPressed: () {},
    )

我希望此按钮在按下时将文本颜色更改为白色

1 个答案:

答案 0 :(得分:2)

我认为最好的选择是从RawMaterialButton

创建自己的自定义按钮
Color buttonColor = Colors.redAccent;



RawMaterialButton(
  child: Text(
  'Delete',
  style: TextStyle(color: buttonColor),
  ),
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(4.0),
    side: BorderSide(color: Colors.redAccent, width: 1)),
  fillColor: Colors.transparent,
  elevation: 0,
  highlightElevation: 0,
  splashColor: Colors.black12,
  onHighlightChanged: (hc) {
     setState(() {
         hc
         ? buttonColor = Colors.white
         : buttonColor = Colors.redAccent;
       });
     },
  highlightColor: Colors.red,
  onPressed: () {},
 )