首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >每日tips:ElevatedButton使用指南

每日tips:ElevatedButton使用指南

作者头像
用户1974410
发布2022-09-20 16:52:08
发布2022-09-20 16:52:08
5410
举报
文章被收录于专栏:flutter开发精选flutter开发精选

ElevatedButton 用来替代老得 RaisedButton widget。它的API和之前相比有了一些变化,下面是使用例子:

代码语言:javascript
复制
ElevatedButton(
  style: ElevatedButton.styleFrom(
    primary: Colors.black, // background (button) color
    onPrimary: Colors.white, // foreground (text) color
  ),
  onPressed: () => print('pressed'),
  child: const Text('Add to Cart'),
)

如果是想在app里使用和之前 ElevatedButton一样的style?

我们只需要设置 MaterialAppThemeData.elevatedButtonTheme 属性:

代码语言:javascript
复制
MaterialApp(
  theme: ThemeData(
    elevatedButtonTheme: ElevatedButtonThemeData(
      style: ElevatedButton.styleFrom(
        primary: Colors.black, // background (button) color
        onPrimary: Colors.white, // foreground (text) color
      ),
    ),
  ),
)

❝Note: 有许多属性都可以自定义的. 可以查看ButtonStyle的文档获取更多信息。 ❞

Happy coding!

少年别走,交个朋友~

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-01-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 flutter开发精选 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档