【问题标题】:Flutter: The side property of OutlineButton seems to have no effectFlutter:OutlineButton的side属性好像没有效果
【发布时间】:2019-04-06 01:44:45
【问题描述】:

产生一个带有白色边框的OutlineButton

OutlineButton(
  shape: RoundedRectangleBorder(
    side: BorderSide(
      color: Colors.purple
    )
  ),
)

产生一个带有紫色边框的FlatButton

FlatButton(
  shape: RoundedRectangleBorder(
    side: BorderSide(
      color: Colors.purple
    )
  ),
)

OutlineButton的部分文档:

borderSide → BorderSide 定义按钮启用但未按下时的边框颜色,以及边框轮廓的宽度和样式。 [...] 最终

【问题讨论】:

  • 对我来说,处理完onPressed之后,边框颜色开始出现,当然需要borderSizeshape
  • @onmyway133 嘿,你可以在下面看到官方答案。那时我混淆了side和borderside属性。无论如何,谢谢。

标签: flutter button dart


【解决方案1】:

OutlineButton 有一个名为borderSide 的属性,你可以直接使用它:

        OutlineButton(
          borderSide: BorderSide(
              color: Colors.purple
            ),
        )

https://docs.flutter.io/flutter/material/OutlineButton/borderSide.html

【讨论】:

  • 我把他们弄糊涂了,这太荒谬了,哈哈。无论如何,谢谢!
【解决方案2】:

像这样处理onPressed:(){}。 颜色会出现。 稍后您可以更改 onPressed 中的功能。 干杯...

【讨论】:

    【解决方案3】:

    Flutter 2.0 不推荐使用OutlineButton,您应该改用OutlinedButton

    注意:如果您使用shape 属性并希望给边框上色,那么您应该将side 属性放置在两个位置以产生效果。像这样:

      OutlinedButton(
        style: OutlinedButton.styleFrom(
          shape: RoundedRectangleBorder(
                   borderRadius: BorderRadius.all(Radius.circular(14)),
                   side: BorderSide(color: Colors.black, width: 1.0), // HERE
              ),
          side: BorderSide(color: Colors.black, width: 1.0)), // AND HERE
         onPressed: () {},
         child: Text(
           'Details',
           style: TextStyle(
              fontSize: 15,
              fontWeight: FontWeight.w600,
              color: Colors.black,
         ),
       ),
     ),
    

    【讨论】:

      猜你喜欢
      • 2016-05-19
      • 1970-01-01
      • 2011-04-17
      • 2012-03-10
      • 2018-11-05
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      相关资源
      最近更新 更多