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

心不动则不痛 提交于 2020-12-26 05:56:06

问题


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:


回答1:


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.




回答2:


Clean the project cache by running

flutter clean cache

Then invalidate caches / restart Android Studio or VS Code.




回答3:


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



回答4:


  1. Go to file Settings
  2. Search Flutter (in the search bar)
  3. Provide Flutter SDK path




回答5:


Actually, I reinstalled the flutter SDK to solve the problem. After a few days, the same error occurred, but then I Started hovering over the red line, after a minute, the error was solved automatically. I guess the SDK connects with internet to check for all the libraries and syntax stuff once we open the IDE.




回答6:


It happens because of the old cache. Just clean the cache with the following command

flutter clean cache



回答7:


I just had the same issue. It looks like I changed a flutter lib file by mistake.

To fix this, without reinstalling Flutter SDK:

  • go to your Flutter SDK installation path
  • open terminal and type: git status
  • it will show the modified files in red (ex: modified: packages/flutter/lib/src/widgets/basic.dart
  • revert modifications file using: git checkout FILE_PATH (ex: git checkout packages/flutter/lib/src/widgets/basic.dart)


来源:https://stackoverflow.com/questions/51480043/the-named-parameter-child-isnt-defined-in-center-constructor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!