首页 > 解决方案 > 如何在 Flutter 中创建带边框的圆形按钮?

问题描述

我发现如何在 Flutter 中创建圆形图标按钮?其中有这个代码:

RawMaterialButton(
  onPressed: () {},
  elevation: 2.0,
  fillColor: Colors.white,
  child: Icon(
    Icons.pause,
    size: 35.0,
  ),
  padding: EdgeInsets.all(15.0),
  shape: CircleBorder(),
)

效果很好,但我不能插入带颜色的边框。查看https://api.flutter.dev/flutter/painting/CircleBorder-class.html我找不到任何插入边框的方法。

在 Flutter 中的圆形按钮中插入边框的最简单方法是什么?

标签: flutterdart

解决方案


您可以通过将 side 属性应用于 CircleBorder 来设置边框。请参阅下面的代码。

     RawMaterialButton(
      onPressed: () {},
      elevation: 2.0,
      fillColor: Colors.white,
      child: Icon(
        Icons.pause,
        size: 35.0,
      ),
      padding: EdgeInsets.all(15.0),
      shape: CircleBorder(
        side: BorderSide(width: 5, color: Colors.red, style: BorderStyle.solid),
      ),
    );

推荐阅读