【发布时间】:2026-02-14 16:20:05
【问题描述】:
我是 Flutter 的新手,所以我正在尝试创建一个显示警报对话框的小部件。在警报对话框的内容中,我得到了 SingleChildScrollView,在所谓的按钮栏中,我有一个文本、复选框和一个按钮,我想对齐它们(将带有文本的复选框放在左侧,按钮放在右侧),但我不知道怎么做。尝试扩展和灵活,还尝试插入将 mainAxisAlignment 设置为 spaceEvenly 的行,不工作,有人可以帮我吗?
代码如下:
class TermsAndConditionsAlertDialog extends StatefulWidget {
TermsAndConditionsAlertDialogState createState() {
return new TermsAndConditionsAlertDialogState();
}
}
class TermsAndConditionsAlertDialogState
extends State<TermsAndConditionsAlertDialog> {
static bool _isChecked = false;
//TODO get the terms and conditions message
static final String _TERMS_AND_CONDITIONS_MESSAGE =
'blablabla this is a terms and conditions message and a blablababl and a bla bla and a aaaaaaaaaaaa bla';
static final String _DIALOG_TITLE = 'Terms and Conditions';
@override
Widget build(BuildContext context) {
// TODO: implement build
return new AlertDialog(
title: new Text(_DIALOG_TITLE),
content: new SingleChildScrollView(
child: new Text(
_TERMS_AND_CONDITIONS_MESSAGE,
style: new TextStyle(fontSize: 50.0),
),
),
actions: <Widget>[
new Text('Accept'),
new Checkbox(
// title: Text('Accept'),
value: _isChecked,
onChanged: (bool newValue) {
setState(() {
_isChecked = newValue;
});
},
),
new RaisedButton(
onPressed: () {
_printDialogResult();
_closeDialog();
//TODO add a method to move on with an app
},
child: new Text(
'Start',
style: TextStyle(color: Colors.white),
)),
],
);
}
void _printDialogResult() {
//simply prints the result in console
print('You selected 1');
}
void _closeDialog() {
if (_isChecked) {
Navigator.pop(context);
}
}
}[FL][1]
【问题讨论】:
-
我认为你可以使用 simpledialog 代替 alert,通过简单的对话框你可以自定义任何你想要的小部件
-
可能是重复的,但是,实际上我没有发现任何 cmets 工作和任何足够的说明,所以我创建了这个.. 将尝试使用 SimpleDialog 运行测试用例,谢谢))