我目前正在开发一款处于Ffltter中的Android应用程序.我怎么才能添加一个圆形的按钮呢?

推荐答案

1. Solution Summary

FlatButtonRaisedButton已弃用.

因此,您可以将放置在style属性中的shape用于TextButtonElevatedButton.

自Ffltter 2.0以来,有一些更改:

2. Rounded Button

style属性内有shape属性:

style: ButtonStyle(
  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
    RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(18.0),
      side: BorderSide(color: Colors.red)
    )
  )
)

Enter image description here

Square Button

对于方形按钮,您可以使用ElevatedButton或以其他方式添加:

style: ButtonStyle(
  shape: MaterialStateProperty.all<RoundedRectangleBorder>(
    RoundedRectangleBorder(
      borderRadius: BorderRadius.zero,
      side: BorderSide(color: Colors.red)
    )
  )
)

Enter image description here

Complete Example

Row(
  mainAxisAlignment: MainAxisAlignment.end,
  children: [
    TextButton(
      child: Text(
        "Add to cart".toUpperCase(),
        style: TextStyle(fontSize: 14)
      ),
      style: ButtonStyle(
        padding: MaterialStateProperty.all<EdgeInsets>(EdgeInsets.all(15)),
        foregroundColor: MaterialStateProperty.all<Color>(Colors.red),
        shape: MaterialStateProperty.all<RoundedRectangleBorder>(
          RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(18.0),
            side: BorderSide(color: Colors.red)
          )
        )
      ),
      onPressed: () => null
    ),
    SizedBox(width: 10),
    ElevatedButton(
      child: Text(
        "Buy now".toUpperCase(),
        style: TextStyle(fontSize: 14)
      ),
      style: ButtonStyle(
        foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
        backgroundColor: MaterialStateProperty.all<Color>(Colors.red),
        shape: MaterialStateProperty.all<RoundedRectangleBorder>(
          RoundedRectangleBorder(
            borderRadius: BorderRadius.zero,
            side: BorderSide(color: Colors.red)
          )
        )
      ),
      onPressed: () => null
    )
  ]
)

Flutter相关问答推荐

如何在SingleChildScrollView中使用GridView

手势捕获的异常:类型';Double';不是类型转换中类型';Double';的子类型

在Android Studio的新用户界面中未找到热重新加载

如何将Visual Studio代码中Flutter 应用的包名从com.example.XXX更改为Play Store中受限制的包名称

使小部件处于有状态状态会导致hasSize异常

Ffmpeg_kit_fltter:^6.0.3版权问题

通过Ffltter应用程序与Docker服务器进行交互以进行身份验证

在flutter web上渲染多个Youtube视频

摆动更改标记可轻敲文本按钮样式

在Flutter 中创建自定义形状

Flutter为什么不;没有ListView.iterable()构造函数?

带有命名参数的回调函数不起作用

Flutter 火焰相机抖动已弃用

Flutter: pie_chart 插件动画滚动问题

如何计算 Firestore 集合中的文档数量?

MediaQuery 在不同手机上不一致

Flutter 中的 Firebase 后台消息处理程序产生重复的隔离并运行应用程序两次

NoSuchMethodError:方法 '[]' 在 null 上被调用.我的信息流中的错误

使用 mocktail 包进行单元测试时,类型Null不是Future类型的子类型

Flutter Web Responsiveness 效率不高