Futter基础第14篇: 中的按钮组件 RaisedButton、FlatButton、OutlineButton、IconButton、ButtonBar以及自定义按钮组件

效果图:

在这里插入图片描述

import 'package:flutter/material.dart';

class ButtonDemoPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('按钮演示页面'),

        actions: <Widget>[
          IconButton(           //图标按钮
            icon: Icon(Icons.settings),
            onPressed: (){

            },
          )
        ],
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,    //垂直居中
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.center,  //水平居中
            children: <Widget>[
              RaisedButton(
                child: Text('普通按钮'),
                onPressed: (){
                  print('普通按钮');
                },
              ),
              SizedBox(width: 10,),
              RaisedButton(
                child: Text('颜色按钮'),
                color: Colors.blue, //背景颜色
                textColor: Colors.white,  //字体白色
                onPressed: (){
                  print('颜色按钮');
                },
              ),
              SizedBox(width: 10,),
              RaisedButton(
                child: Text('阴影按钮'),
                color: Colors.blue, //背景颜色
                textColor: Colors.white,  //字体白色
                elevation: 10,  //设置阴影效果,值越大阴影效果越好
                onPressed: (){
                  print('阴影按钮');
                },
              ),
            ],
          ),
          RaisedButton.icon(
//              onPressed: null,
              icon: Icon(Icons.search),
              label: Text('图标按钮'),
            color: Colors.blue,
              textColor: Colors.white,
            onPressed: (){
                print('图标按钮');
            },
          ),
          SizedBox(height: 5,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Container(      //利用容器来设置按钮的宽度和高度
                height: 50,
                width: 300,
                child: RaisedButton(
                  child: Text('宽度高度'),
                  color: Colors.blue,
                  textColor: Colors.white,
                  elevation: 20,
                  onPressed: (){
                    print('宽度高度');
                  },
                ),
              )
            ],
          ),
          SizedBox(height: 5,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
             Expanded(            //铺满屏幕宽度
               child: Container(    //利用容器设置高度
                 height: 80,
                 margin: EdgeInsets.all(10),    //设置:左右间距10
                 child:  RaisedButton(
                   child: Text('自适应按钮'),
                   color: Colors.blue,
                   textColor: Colors.white,
                   elevation: 20,
                   onPressed: (){
                     print('自适应按钮');
                   },
                 ),
               )
             )
            ],
          ),
          SizedBox(height: 10,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                child: Text('圆角按钮'),
                color: Colors.blue,
                textColor: Colors.white,
                elevation: 20,
                shape: RoundedRectangleBorder(      //圆角按钮
                  borderRadius: BorderRadius.circular(10)     //圆角弧度
                ),
                onPressed: (){
                  print('圆角按钮');
                }),
              SizedBox(width: 10,),
             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('扁平化按钮');
                },
              )
            ],
          ),
          SizedBox(height: 10,),
          OutlineButton(        //带边框按钮
            child: Text('边框按钮'),
//            color: Colors.red,  没有效果,这就是边框按钮的特性,不仅自带边框,还无法设置它的背景颜色,我猜可能是作者怕设置的背景颜色跟边框颜色一致
//          textColor: Colors.yellow,   //有效果
            onPressed: (){
              print('边框按钮');
            },
          ),
          SizedBox(height: 5,),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Expanded(                   //自适应水平平铺
                child: Container(
                  margin: EdgeInsets.all(20),   //上下左右分别间距 20
                  height: 50,
                  child: OutlineButton(
                    child: Text('注册'),
                    onPressed: (){

                    },
                  ),
                ),
              )
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ButtonBar(
                children: <Widget>[
                  RaisedButton(
                    child: Text('登录'),
                    color: Colors.blue,
                    textColor: Colors.white,
                    elevation: 20,
                    onPressed: (){
                      print('登录');
                    },
                  ),
                  RaisedButton(
                    child: Text('注册'),
                    color: Colors.blue,
                    textColor: Colors.white,
                    elevation: 20,
                    onPressed: (){
                      print('注册');
                    },
                  ),
                  MyButton(text:'自定义按钮',height: 60.0,width: 100,pressed: (){
                    print('自定义按钮');
                  })
                ],
              )
            ],
          )
        ],
      ),
    );
  }
}

//自定义按钮组件

class MyButton extends StatelessWidget {
  final text;
  final pressed;
  final double width;
  final double height;
  const MyButton({this.text="",this.pressed=null,this.width=80.0,this.height=30.0});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: this.height,
      width: this.width,
      child: RaisedButton(
        child: Text(this.text),
        onPressed: this.pressed,
      ),
    );
  }
}
Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计,皆可应用在项目、毕业设计、课程设计、期末/期/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

王睿丶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值