gpt4 book ai didi

flutter - 如何在 flutter 中显示 snackbar 的无限持续时间?

转载 作者:行者123 更新时间:2023-12-03 02:42:07 25 4
gpt4 key购买 nike

我在android studio中创建了flutter项目并试图显示snackbar无限持续时间。这是我的代码

 final snackBar = SnackBar(
content: Text('Cart:'+countProducts.toString()+" Products($countCost:sum)",style: TextStyle(color: Colors.black),),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft:Radius.circular(22),topRight:Radius.circular(22))),
backgroundColor: Colors.white70,
action: SnackBarAction(
textColor: Colors.blueAccent,
label: "Buy",
onPressed: () {
// Some code to undo the change.
},
),
);

Scaffold.of(context).showSnackBar(snackBar);

还有另一个按钮可以更改 snackbar 文本。但我不想把它驳回。所以如何在 flutter 中显示 snackbar 的无限持续时间

最佳答案

您可以使用 snackbar 上的 Duration 属性

例子

final snackBar = SnackBar(
content: Text('Cart:'+countProducts.toString()+" Products($countCost:sum)",style: TextStyle(color: Colors.black),),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft:Radius.circular(22),topRight:Radius.circular(22))),
backgroundColor: Colors.white70,
action: SnackBarAction(
textColor: Colors.blueAccent,
label: "Buy",
onPressed: () {
// Some code to undo the change.
},
),
duration: Duration(seconds: double.infinity),

//得到问题 int != double
);

使用 Duration(seconds: double.infinity)
不确定这是否是最好的。

编辑

您可以尝试以下而不是使用 double.infinity
Duration(days: 365)

引用
  • Duration
  • 关于flutter - 如何在 flutter 中显示 snackbar 的无限持续时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58777482/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com