Flutter Button 图文分析、效果浏览

417 阅读1分钟

题记:不到最后时刻,千万别轻言放弃,无论结局成功与否,只要你拼博过,尽力过,一切问心无愧


**你可能需要
CSDN网易云课堂教程
掘金EDU学院教程
知乎Flutter系列文章
头条同步百度同步

本文章首发于微信公众号(biglead) 我的大前端生涯 ,同步刊登各技术论坛。


1 Flutter 提供的Button比较多

  Widget buildRaisedButton(){
    //它默认带有阴影和灰色背景。按下后,阴影会变大
    return RaisedButton(
      child: Text("RaisedButto"),
      onPressed: () => {},
    );
  }

在这里插入图片描述



  Widget buildFlatButton(){
    //FlatButton即扁平按钮,默认背景透明并不带阴影。按下后,会有背景色:
    return FlatButton(
      child: Text("登录"),
      onPressed: () => {},
    );
  }

在这里插入图片描述


  Widget buildOutlineButton(){
    //OutlineButton默认有一个边框,不带阴影且背景透明。按下后,边框颜色会变亮、同时出现背景和阴影(较弱):
    return OutlineButton(
      child: Text("登录"),
      onPressed: () => {},
    );
  }

在这里插入图片描述


  Widget buildIconButton(){
    return IconButton(
      icon: Icon(Icons.thumb_up),
      onPressed: () => {},
    );
  }

在这里插入图片描述

2 为FlatButton设置一个圆角背景

在这里插入图片描述

  Widget buildCustomButton(){
    return FlatButton(
      //按钮文字颜色
      textColor: Colors.white,
      //按钮禁用时的背景颜色
      disabledColor:Colors.grey,
      //按钮禁用时的文字颜色
      disabledTextColor: Colors.grey,
      //正常状态下的背景颜色
      color: Colors.blue,
      //按钮按下时的背景颜色
      highlightColor: Colors.blue[700],
      //按钮主题,默认是浅色主题
      colorBrightness: Brightness.dark,
      //外形
      splashColor: Colors.grey,
      // button 显示的文字
      child: Text("Submit"),
      //圆角边框
      shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
      //按钮点击回调
      onPressed: () => {},
    );
  }

公众号 我的大前端生涯