【问题标题】:The named parameter 'child' isn't defined. Try correcting the name to an existing named parameter's name未定义命名参数“child”。尝试将名称更正为现有命名参数的名称
【发布时间】:2021-05-13 13:01:14
【问题描述】:

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

未定义命名参数“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;
              })
        ],
      ),
    );
  }

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    child 已弃用。您应该改用builderDocs 中提到了 showDialog。

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

    【讨论】:

    • 为方便起见,您可以将 child: new AlertDialog( 替换为 builder: (context) =&gt; AlertDialog(
    猜你喜欢
    • 2021-01-08
    • 2022-07-06
    • 1970-01-01
    • 2021-06-15
    • 2023-04-11
    • 2020-09-03
    • 2023-02-07
    • 2022-08-22
    • 1970-01-01
    相关资源
    最近更新 更多