如何将动作按钮居中摆在警报对话框中?

时间:2020-02-10 22:14:26

标签: flutter

我想在警报对话框中居中放置一个平面按钮 我尝试了以下代码,但无法正常工作

        actions: <Widget>[
          Container(
            alignment: Alignment.center,
            child: FlatButton(
              child: Text('something'),
              onPressed: (){},
            ),
          ),
        ],

2 个答案:

答案 0 :(得分:0)

怎么样?

AlertDialog(
  title: FlatButton(
    child: Text('something'),
    onPressed: () {},
  ),
);

AlertDialog(
  content: FlatButton(
    child: Text('something'),
    onPressed: () {},
  ),
);

答案 1 :(得分:0)

使用CupertinoAlertDialog代替AlertDialog更加简单

CupertinoAlertDialog(
        title: Text("Alert !",
            style: AppTheme.normalTextStyle()
                .copyWith(fontWeight: FontWeight.bold, fontSize: 15)),
        content: Text(
          "Are you sure you want to logout?",
          style: AppTheme.normalTextStyle(),
        ),
        actions: <Widget>[
          FlatButton(
            child: Text("Yes", style: AppTheme.normalTextStyle()),
            onPressed: () {
              Navigator.of(context).pushAndRemoveUntil(
                  MaterialPageRoute(builder: (context) => LogInScreen()),
                  (Route<dynamic> route) => false);
            },
          ),
          FlatButton(
            child: Text("No", style: AppTheme.normalTextStyle()),
            onPressed: () {
              Navigator.of(context).pop();
            },
          )
        ],
      );