小编awa*_*aik的帖子

Flutter TextButton 去除内边距和内边距

我刚刚在 Flutter 中更新了我的代码以使用 TextButton 而不是 old FlatButton。我不知道如何设置按钮的宽度和高度。

我有两个问题。第一个是我现在有这个图标按钮:

TextButton.icon(
    label: Container(),
    style: TextButton.styleFrom(padding: EdgeInsets.all(0),
        backgroundColor: Colors.black26),
        icon: Icon(Icons.share, color: Theme.of(context).primaryColor),
        onPressed: () {}),
Run Code Online (Sandbox Code Playgroud)

就像这样: 在此处输入图片说明

我不知道如何摆脱左侧和右侧的填充。虽然我确实将样式内的填充设置为零。

我的第二个问题是我有一个这样的按钮:

ButtonTheme(
    materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
    height: 10,
    minWidth: 15,
    padding: EdgeInsets.only(top: 5, bottom: 5, right: 5, left: 5),
    child: FlatButton(
      color: Colors.white.withOpacity(0.9),
      child: <MyChild>,
      onPressed: () {},
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(12.0),
          side: BorderSide(
              color: condition
                  ? Theme.of(context).primaryColor
                  : widget.color != null
                      ? widget.color
                      : Colors.black54,
              width: 0.5)),
    ));
}
Run Code Online (Sandbox Code Playgroud)

它看起来像这样: 在此处输入图片说明

现在我将代码更新为:

OutlinedButton(
    style: OutlinedButton.styleFrom(
      tapTargetSize: …
Run Code Online (Sandbox Code Playgroud)

flutter

15
推荐指数
3
解决办法
1万
查看次数

标签 统计

flutter ×1