Flutter--按钮组件

属性
属性释义
onPressed按钮点击响应事件
textColor按钮显示文本的颜色
color按钮的颜色
diabledColor按钮禁用时的颜色
disabledTextColor按钮禁用时的文本颜色
splashColor水波纹颜色
highlightColor长按显示的颜色
elevation阴影的范围,值越大阴影范围越大
shape设置按钮的形状
按钮使用实例
import 'package:flutter/material.dart';

class ButtonDemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("按钮"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[


                RaisedButton(
                  child: Text("RaiseButton"),
                  color: Colors.red,
                  textColor: Colors.white,
                  elevation: 20,
                  onPressed: () {
                    print("click");
                  },
                ),
                RaisedButton(
                    child: Text('圆角按钮'),
                    color: Colors.blue,
                    textColor: Colors.white,
                    elevation: 20,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10)),
                    onPressed: () {
                      print("圆角按钮");
                    }),
                Container(
                  height: 80,
                  child: RaisedButton(
                      child: Text('圆形按钮'),
                      color: Colors.blue,
                      textColor: Colors.white,
                      elevation: 20,
                      splashColor: Colors.red,
                      shape:
                          CircleBorder(side: BorderSide(color: Colors.white)),
                      onPressed: () {
                        print("圆形按钮");
                      }),
                ),
                FlatButton(
                  child: Text("扁平按钮"),
                  color: Colors.blue,
                  textColor: Colors.yellow,
                  onPressed: () {
                    print('FlatButton');
                  },
                ),
                OutlineButton(
                    child: Text("线框按钮"),
                    textColor: Colors.yellow,
                    onPressed: () {
                      print('FlatButton');
                    }),
                MyCustomButton(text: "自定义按钮",height: 60.0,width: 100.0,pressed: (){
                  print('自定义按钮');
                })
              ],
            ),
      )
    );
  }
}

//自定义按钮组件


class MyCustomButton extends StatelessWidget {
  final text;
  final pressed;
  final width;
  final height;

  const MyCustomButton(
      {this.text = '', this.pressed = null, this.width = 80, this.height = 30});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: this.height,
      width: this.width,
      child: RaisedButton(
        child: Text(this.text),
        onPressed: this.pressed,
      ),
    );
  }
}

在这里插入图片描述

FloatingActionButton
属性
属性释义
tooltipFab长按时显示,无障碍功能
backgroundColor背景颜色
elevation未点击的时候的阴影
hignlightElevation点击时阴影值,默认12.0
onPressed点击事件回调
shapeFab形状
mini显示大小类型
return Scaffold(
    appBar: AppBar(
      title: Text("按钮"),
    ),
    floatingActionButton: Container(
      height: 80,
      width: 80,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(40),
        color: Colors.white,
      ),
      margin: EdgeInsets.only(top: 10),
      padding: EdgeInsets.all(8),
      child: FloatingActionButton(
        child: Icon(Icons.add),
        backgroundColor: Colors.yellow,
      ),
    ),
    // fab在底部居中
    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
body: ...,

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wjxbless

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值