Flutter之按钮组件

1、常用按钮

常用按钮介绍

 

RaisedButton

凸起的按钮,其实就是 Material Design 风格的 Button 

FlatButton 

扁平化的按钮

OutlineButton

线框按钮

IconButton 

图标按钮

FloatingActionButton

浮动按钮

ButtonBar

按钮组 

2、按钮中常用的属性 

属性名称值类型属性值

onPressed

VoidCallback ,一般接收一个 方法

必填参数,按下按钮时触发的回调,接收一个 方法,传 null 表示按钮禁用,会显示禁用相关 样式

child

Widget

文本控件

textColor

Color

文本颜色

color

Color

按钮的颜色

disabledColor

Color

按钮禁用时的颜色

disabledTextColor

Color

按钮禁用时的文本颜色

splashColor

Color

点击按钮时水波纹的颜色

highlightColor

Color

点击(长按)按钮后按钮的颜色

elevation

double

阴影的范围,值越大阴影范围越大

padding

 

内边距

shape

 

设置按钮的形状

shape: RoundedRectangleBorder(

borderRadius: BorderRadius.circular(10), )

shape: CircleBorder(

      side: BorderSide(

color: Colors.white, )

)

import 'package:flutter/material.dart';

class ButtonPage extends StatelessWidget {
  ButtonPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Button"),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.settings),
            onPressed: (){
            },
          )
        ],
      ),
      body: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              RaisedButton(
                textColor: Colors.white,
                color: Colors.blue,
                child: Text("RaisedButton"),
                onPressed: () {
                  print("RaisedButton");
                },
              ),
              SizedBox(width: 10,),
              FlatButton(
                textColor: Colors.white,
                color: Colors.blue,
                child: Text("FlatButton"),
                onPressed: () {
                  print("FlatButton");
                },
              ),
              SizedBox(width: 10,),
              OutlineButton(
                textColor: Colors.blue,
                color: Colors.blue,
                child: Text("OutlineButton"),
                onPressed: () {
                  print("OutlineButton");
                },
              ),
            ],
          ),
          Row(
            children: <Widget>[
              Expanded(child: Container(
                margin: EdgeInsets.all(10),
                child: RaisedButton(
                  textColor: Colors.white,
                  color: Colors.blue,
                  child: Text("自适应RaisedButton"),
                  onPressed: () {
                    print("RaisedButton");
                  },
                ),
              )),
            ],
          ),
          FloatingActionButton(
            onPressed: (){
            },
            child: Text("浮动"),
          ),
          ButtonBar(
            alignment:MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                textColor: Colors.white,
                color: Colors.blue,
                child: Text("ButtonBar1"),
                onPressed: () {
                  print("ButtonBar1");
                },
              ),
              RaisedButton(
                textColor: Colors.white,
                color: Colors.blue,
                child: Text("ButtonBar2"),
                onPressed: () {
                  print("ButtonBar2");
                },
              ),
              MyButton(hight: 30,width: 100,onPressed: "自定义按钮",color: Colors.yellow,),
            ],
          )
        ],
      ),
    );
  }
}

//自定义按钮
class MyButton extends StatelessWidget {
  final double hight;
  final double width;
  final buttonName;
  final onPressed;
  final Color color;
  MyButton({Key key, this.hight=20, this.width=20, this.buttonName="按钮", this.onPressed, this.color=Colors.blue}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: hight,
      width: width,
      child: RaisedButton(
        color: color,
        child: Text(buttonName),
        onPressed: (){
          print((onPressed));
        }
        ,
      ),
    );
  }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值