(15)各种Button 与排列 OutlineButton,ButtonBar,Expanded,RaisedButton,StadiumBorder,FlatButton.icon

效果

至于倒数第二行和倒数第一行的效果为啥一样。。可能是fluttersdk升级了。。之前的api不再生效。。算是留坑!

代码

import 'package:flutter/material.dart';

class ButtonDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final Widget _floatButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      FlatButton(
        onPressed: () {},
        child: Text("FlatButton"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        color: Colors.black87,
      ),
      FlatButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("FlatButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        color: Colors.black87,
      )
    ]);

    final Widget _raisedButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      Theme(
          // data: ThemeData(),
          data: Theme.of(context).copyWith(
              buttonColor: Theme.of(context).accentColor,
              buttonTheme: ButtonThemeData(
                textTheme: ButtonTextTheme.primary,
                // shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                shape: StadiumBorder(),
              )),
          child: RaisedButton(
            onPressed: () {},
            child: Text("RaisedButton"),
            splashColor: Colors.grey,
            textColor: Theme.of(context).accentColor,
            // color: Colors.white,
            // textTheme: ButtonTextTheme.primary,
            elevation: 0.0,
          )),
      SizedBox(
        width: 16.0,
      ),
      RaisedButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("RaisedButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
        elevation: 12.0,
      )
    ]);

    final Widget _outerLineButtonDemo =
        Row(mainAxisAlignment: MainAxisAlignment.center, children: [
      Theme(
          // data: ThemeData(),
          data: Theme.of(context).copyWith(
              buttonColor: Theme.of(context).accentColor,
              buttonTheme: ButtonThemeData(
                textTheme: ButtonTextTheme.primary,
                // shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
                shape: StadiumBorder(),
              )),
          child: OutlineButton(
            onPressed: () {},
            child: Text("OutlineButton"),
            splashColor: Colors.grey[100],
            textColor: Colors.black,
            borderSide: BorderSide(color: Colors.black),
            highlightedBorderColor: Colors.grey,
            // textTheme: ButtonTextTheme.primary,
          )),
      SizedBox(
        width: 16.0,
      ),
      OutlineButton.icon(
        icon: Icon(Icons.add),
        onPressed: () {},
        label: Text("OutlineButton.icon"),
        splashColor: Colors.grey,
        textColor: Theme.of(context).accentColor,
      )
    ]);

    final Widget _widthOuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          width: 200,
          child: OutlineButton(
            onPressed: () {},
            child: Text("_widthOuterLineButton"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    final Widget _expendOuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          child: OutlineButton(
            onPressed: () {},
            child: Text("_expendOuterLineButton"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    final Widget _expend2OuterLineButton = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Expanded(
          flex: 1,
          child: OutlineButton(
            onPressed: () {},
            child: Text("权重 for 1"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        ),
        SizedBox(
          width: 15,
        ),
        Expanded(
          //权重属性
          flex: 2,
          child: OutlineButton(
            onPressed: () {},
            child: Text("权重 for 2"),
            splashColor: Colors.grey,
            textColor: Colors.blue,
          ),
        )
      ],
    );
    //一行并列行显示的按钮
    final Widget _buttonBar = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        ButtonBar(
          children: [
            OutlineButton(
              onPressed: () {},
              child: Text("ButtonBar"),
              splashColor: Colors.grey,
              textColor: Colors.blue,
            ),
            OutlineButton(
              onPressed: () {},
              child: Text("ButtonBar"),
              splashColor: Colors.grey,
              textColor: Colors.blue,
            ),
          ],
        )
      ],
    );
    //对刚才的并排中间添加边距
    final Widget _buttonBarPaddingv = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Theme(
          data: Theme.of(context).copyWith(
              buttonTheme: ButtonThemeData(
                  padding: EdgeInsets.symmetric(horizontal: 100.0))),
          child: ButtonBar(
            children: [
              OutlineButton(
                onPressed: () {},
                child: Text("ButtonBar"),
                splashColor: Colors.grey,
                textColor: Colors.blue,
              ),
              OutlineButton(
                onPressed: () {},
                child: Text("ButtonBar"),
                splashColor: Colors.grey,
                textColor: Colors.blue,
              ),
            ],
          ),
        )
      ],
    );
    return Scaffold(
      appBar: AppBar(
        title: Text("button Demo"),
        elevation: 0.0,
      ),
      body: Container(
        padding: EdgeInsets.all(16.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            _floatButtonDemo,
            _raisedButtonDemo,
            _outerLineButtonDemo,
            _widthOuterLineButton,
            _expendOuterLineButton,
            _expend2OuterLineButton,
            _buttonBar,
            _buttonBarPaddingv
          ],
        ),
      ),
    );
  }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

安果移不动

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

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

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

打赏作者

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

抵扣说明:

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

余额充值