Flutter 如何在颤振中显示snackbar无限持续时间?
我在android studio中创建了颤振项目,并试图显示snackbar无限持续时间。这是我的代码Flutter 如何在颤振中显示snackbar无限持续时间?,flutter,dart,snackbar,Flutter,Dart,Snackbar,我在android studio中创建了颤振项目,并试图显示snackbar无限持续时间。这是我的代码 final snackBar = SnackBar( content: Text('Cart:'+countProducts.toString()+" Products($countCost:sum)",style: TextStyle(color: Colors.black),), shape: RoundedRectangleBorder( bor
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文本。但是我不想将其驳回。因此,如何在颤振中显示snackbar infinite duration您可以使用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.infinity
Duration(days: 365)
参考文献