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

Try Restarting your Analysis Dart Server.

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

Image


Clean the project cache by running

flutter clean cache

Then invalidate caches / restart Android Studio or VS Code.


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

Tags:

Dart

Flutter