Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The named parameter 'child' isn't defined. in Center() constructor

Tags:

flutter

dart

I ran flutter upgrade today, and now I am getting an error that says-

[dart] The named parameter 'child' isn't defined.

The project is newly created and the default code is untouched, but it still has the same Error:

like image 591
HRISHIKESH DESHMUKH Avatar asked Jul 23 '18 13:07

HRISHIKESH DESHMUKH


3 Answers

In my case it happens when I name the widget with the same name of a flutter component, like so:

class OutlineButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OutlineButton(
      child: Text('+R\$ 5'),
      onPressed: () {},
      borderSide: BorderSide(color: Colors.grey),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(30.0),
      ),
    );
  }
}

You need to change the name of the created component with a different name, for example:

class CustomOutlineButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return OutlineButton(
      child: Text('+R\$ 5'),
      onPressed: () {},
      borderSide: BorderSide(color: Colors.grey),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(30.0),
      ),
    );
  }
}
like image 159
Felipe Augusto Avatar answered Oct 20 '22 04:10

Felipe Augusto


Clean the project cache by running

flutter clean cache

Then invalidate caches / restart Android Studio or VS Code.

like image 23
Taif Raoof Avatar answered Oct 21 '22 05:10

Taif Raoof


Try Restarting your Analysis Dart Server.

  1. At the bottom of Android Studio click on the Dart Analysis tab
  2. Click on the Restart icon.

Image

like image 19
Hector Avatar answered Oct 21 '22 05:10

Hector