如何在SnackBar上设置高度,以及如何在SnackBar上以文本为中心?我也使用了Positioned和SozedBox。
_showSnackBar(GlobalKey<ScaffoldState> _scaffoldKey) {
final snackBar = SnackBar(
content:SizedBox(child:Container(
child: Center(
child: Text("Connection dropped.", style:
TextStyle(color: Colors.white,fontWeight: FontWeight.bold),textAlign: TextAlign.center,)),height: 1.0),),
duration: Duration(seconds: 10),
backgroundColor: Colors.red,
);
_scaffoldKey.currentState.showSnackBar(snackBar);
}
答案 0 :(得分:0)
只需执行以下操作:
final snackBar = SnackBar(
content: Container(
height: 50.0,
child: Center(
child: Text(
"Connection dropped.",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
)),
),
duration: Duration(seconds: 10),
backgroundColor: Colors.red,
);
_scaffoldKey.currentState
.showSnackBar(snackBar);
答案 1 :(得分:0)