未定义命名参数“child”。尝试将名称更正为现有命名参数的名称

我有一个简单的对话框小部件,它在 beta 通道的 Windows 上运行良好,没有错误,但是当我在 MacBook 上拉相同的 repo 时,我以错误结束。两个环境都在测试版频道上

未定义命名参数“child”。尝试将名称更正为现有命名参数的名称,或使用名称“child”定义命名参数

我的对话。什么可能导致孩子抱怨child: new AlertDialog(

void _showDialog(
      BuildContext context, QRViewController controller, String result) async {
    await showDialog<String>(
      context: context,
      // FIXME: child isn't defined for this function. need to use right params
        child: new AlertDialog(
        contentPadding: const EdgeInsets.all(16.0),
        content: Container(
          height: 400,
          child: Column(
            children: [
              new Row(
                children: [
                  Text(
                    'Please record your body temperature nin Celsius from the digital reading non the infrared thermometer',
                  ),
                ],
              ),
              new Row(
                children: <Widget>[
                  new Expanded(
                    child: new TextField(
                      autofocus: true,
                      onChanged: (value) {
                        temp = value;
                      },
                      decoration: new InputDecoration(hintText: 'C'),
                      keyboardType: TextInputType.number,
                      inputFormatters: <TextInputFormatter>[
                        FilteringTextInputFormatter.allow(
                            RegExp(r'^d+.?d*')),
                      ],
                    ),
                  )
                ],
              ),
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Image.asset("assets/images/temp_checkin.jpg",
                        height: 250, fit: BoxFit.scaleDown),
                  ),
                ],
              )
            ],
          ),
        ),
        actions: <Widget>[
          new FlatButton(
              child: const Text('CANCEL'),
              onPressed: () {
                _QRViewExampleState.capturedQRCode = false;
                Navigator.pop(context);
              }),
          new FlatButton(
              child: const Text('SUBMIT'),
              onPressed: () {
                Navigator.pop(context);
                if (temp != '' && temp != null) {
                  _temperatureCheckIn(result, temp, context);
                }
                _QRViewExampleState.capturedQRCode = false;
              })
        ],
      ),
    );
  }

回答

child已弃用。你应该builder改用。它在showDialog的文档中提到。

void _showDialog(BuildContext context, QRViewController controller, String result) async {
    await showDialog(
        context: context,
        builder: (context) {
            return AlertDialog();
        },
    );
}


以上是未定义命名参数“child”。尝试将名称更正为现有命名参数的名称的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>