08-按钮变小设置

Catalogue
  1. 1. 1,通过上边的了解,我们发现,按钮是有外边距的
  2. 2. 2,将文字设置为1,我们发现,按钮是有最小宽度和高度的
  • 参考资料
  • 1,通过上边的了解,我们发现,按钮是有外边距的

    图1

    当前实现的代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Widget getDemo1(){
    return Column(
    children: <Widget>[
    FlatButton(
    child: Text("flat button1"),
    color: Colors.red,
    onPressed: () {},
    ),
    FlatButton(
    child: Text("flat button1"),
    color: Colors.red,
    onPressed: () {},
    )
    ],
    );
    }

    解决办法:添加属性设置:

    materialTapTargetSize:MaterialTapTargetSize.shrinkWrap, //最小包裹

    图1

    实现代码:

    图1

    2,将文字设置为1,我们发现,按钮是有最小宽度和高度的

    图1

    图1

    那么如何设置按钮的大小呢?

    解决办法:

    将FlatButton用ButtonTheme组件包裹起来,并且设置宽度和高度, 以及内边距

    图1

    效果:

    图1

    参考资料