Saliya Wijebandara
Saliya Wijebandara

Reputation: 1

The named parameter 'child' isn't defined

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)),
    ],
  ));

> How To Fix this Problem In flutter child line error. error was The named parameter 'child' isn't defined. The named parameter 'child' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the

Upvotes: 0

Views: 655

Answers (1)

quoci
quoci

Reputation: 3557

I guess you use Flutter 2.0. Since this update AlertDialog doesn't have a child property anymore. Instead you have to declare a builder.

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

Upvotes: 2

Related Questions