未定义命名参数'child'


showDialog(
context: context,
barrierDismissible: false,
child: AlertDialog( // this line error
shape: defaultCardBorder(),
title: Row(
children: [
_icon,
SizedBox(width: 10),
Expanded(child: Text(_title, style: TextStyle(fontSize: 22)))
],
),
content: Text(
message,
style: TextStyle(fontSize: 18),
),
actions: [
/// Negative button
negativeAction == null
? Container(width: 0, height: 0)
: FlatButton(
onPressed: negativeAction,
child: Text(negativeText ?? "CANCEL",
style: TextStyle(fontSize: 18, color: Colors.grey))),
/// Positive button
FlatButton(
onPressed: positiveAction ?? () => Navigator.of(context).pop(),
child: Text(positiveText ?? "OK",
style: _textStyle)),
],
));

>如何解决flutter中的此问题子行错误。错误为未定义命名参数"child"。未定义命名参数"child"。尝试将名称更正为现有命名参数的名称,或使用定义命名参数

我猜您使用的是Flutter 2.0。由于此更新,AlertDialog不再具有子属性。相反,您必须声明一个生成器

showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => AlertDialog(
title: Text('MyTitle'),
content: Container(),
),
);

相关内容

最新更新