问题
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.
- At the the bottom of Android Studio click on the 'Dart Analysis' tab
- 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:
- Go to file Settings
- Search Flutter (in the search bar)
- 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