【问题标题】:How to display snackbar infinite duration in flutter?如何在颤动中显示小吃吧无限持续时间?
【发布时间】:2020-03-05 17:32:46
【问题描述】:

我在 android studio 中创建了颤振项目,并试图显示小吃栏无限持续时间。这是我的代码

 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);

还有另一个按钮可以更改快餐栏文本。但我不想让它消失。那么如何在颤动中显示小吃吧无限持续时间

【问题讨论】:

    标签: flutter dart snackbar


    【解决方案1】:

    您可以使用小吃栏上的 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)
    

    参考

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-04
      • 2022-12-17
      • 2020-10-18
      • 2019-07-24
      • 2021-06-03
      • 2019-04-13
      • 2021-10-24
      • 2017-03-04
      相关资源
      最近更新 更多