我想用3个按钮在Flutter中显示一个AlertDialog,但由于按钮文本占用太多空间而垂直对齐。到目前为止,我只将它们水平显示。知道如何解决吗?这篇文章(How to make an AlertDialog in Flutter?)的解决方案对我不起作用,仍然显示为水平。
static Future<void> showLogoutAllDevicesOrOnlyThisDialog(
BuildContext context) {
var b1 = FlatButton(
textColor: Colors.red,
child: Text('Only on this device'),
onPressed: () {
Navigator.of(context).pop();
RxBus.post(HideSpinnerEvent());
},
);
var b2 = FlatButton(
textColor: Colors.red,
child: Text('On all devices'),
onPressed: () {
Navigator.of(context).pop();
RxBus.post(HideSpinnerEvent());
},
);
var b3 = FlatButton(
child: Text('Cancel'),
onPressed: () {
Navigator.of(context).pop();
},
);
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(''),
content: Text(
"Möchtest du dich auf allen Geräten abmelden oder nur auf diesem Gerät?"),
actions: <Widget>[
b1, b2, b3
],
);
},
);
}
}
答案 0 :(得分:1)
JTable
答案 1 :(得分:1)
您可以创建自己的“自定义对话框”,也可以根据需要创建任何内容,
void _showDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2),
),
elevation: 0,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
child: IntrinsicWidth(
child: IntrinsicHeight(
child: Column(
children: <Widget>[
SizedBox(
height: 10,
),
Text(
"Custom Alert Dialog",
style: TextStyle(
fontWeight: FontWeight.w700,
fontFamily: "Roboto",
fontSize: 18,
),
),
SizedBox(
height: 20,
),
Text(
"This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
style: TextStyle(
fontFamily: "Roboto",
fontWeight: FontWeight.w400,
fontSize: 16,
),
),
SizedBox(
height: 30,
),
Column(
children: <Widget>[
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("OK"),
),
),
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Not Sure"),
),
),
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Cancel"),
),
),
],
)
],
),
),
),
),
);
},
);
您的最终结果将是这个:
但是,如果您正在寻找Row设计,则需要这样的东西:
void _showDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2),
),
elevation: 0,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
child: IntrinsicWidth(
child: IntrinsicHeight(
child: Column(
children: <Widget>[
SizedBox(
height: 10,
),
Text(
"Custom Alert Dialog",
style: TextStyle(
fontWeight: FontWeight.w700,
fontFamily: "Roboto",
fontSize: 18,
),
),
SizedBox(
height: 20,
),
Text(
"This is a message inside your custom Alert Dialog!\nFeel free to change it to fit your needs.",
style: TextStyle(
fontFamily: "Roboto",
fontWeight: FontWeight.w400,
fontSize: 16,
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("OK"),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Not Sure"),
),
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("Cancel"),
),
],
)
],
),
),
),
),
);
},
);
最终结果: