【问题标题】:Flutter SnackBar's heightFlutter SnackBar 的高度
【发布时间】:2021-11-29 00:04:39
【问题描述】:

我的目标

我想以 ListTile 作为内容显示 Flutter 的 default SnackBar。

问题

由于某种原因,Snackbar 几乎比我想要的高三倍,并且似乎 Snackbar 中没有设置高度的参数。

我检查了类似的questions,没有找到一个有效的例子。

小吃店

void showSuccessSnackBar({BuildContext context, String message}) {
  Scaffold.of(context).showSnackBar(
    SnackBar(
      content: Container(
        child: ListTile(
            leading: _successIcon(),
            dense: true,
            title: Text(
              message,
              textAlign: TextAlign.center,
              style: TextStyle(
                color: HATheme.HOPAUT_PINK,
                fontWeight: FontWeight.bold
              ),
            )),
      ),
      behavior: SnackBarBehavior.floating,
      duration: Duration(seconds: 3),
      backgroundColor: Colors.white));
}

Widget _successIcon() {
  return Image.asset(
    'assets/icons/success.png',
    // resizing this doesn't help
    height: 30,
    width: 30,
  );
}

我想要的尺寸:

实际尺寸:

【问题讨论】:

  • 请添加您的代码
  • 忘记了最重要的(facepalm),再检查一遍

标签: flutter dart


【解决方案1】:

您可以为该容器添加高度,您的问题将得到解决

 Container(
    height: 10
    child: ListTile(
        leading: _successIcon(),
        dense: true,
        title: Text(
          message,
          textAlign: TextAlign.center,
          style: TextStyle(
            color: HATheme.HOPAUT_PINK,
            fontWeight: FontWeight.bold
          ),
        )

【讨论】:

  • 尝试了很多解决方案,但没有考虑到这一点。谢谢,它有效。
猜你喜欢
  • 2023-02-09
  • 2018-09-04
  • 2017-10-31
  • 2019-07-04
  • 2015-10-26
  • 2019-12-15
  • 2017-05-09
  • 2020-02-29
  • 1970-01-01
相关资源
最近更新 更多