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

后端 未结 7 778
天涯浪人
天涯浪人 2021-01-17 21:04

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

相关标签:
7条回答
  • 2021-01-17 21:14

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

    flutter clean cache
    
    0 讨论(0)
  • 2021-01-17 21:18

    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)
    0 讨论(0)
  • 2021-01-17 21:20

    Clean the project cache by running

    flutter clean cache
    

    Then invalidate caches / restart Android Studio or VS Code.

    0 讨论(0)
  • 2021-01-17 21:28
    1. Go to file Settings
    2. Search Flutter (in the search bar)
    3. Provide Flutter SDK path

    0 讨论(0)
  • 2021-01-17 21:30

    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.

    0 讨论(0)
  • 2021-01-17 21:31

    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),
          ),
        );
      }
    }
    
    0 讨论(0)
提交回复
热议问题