我是 Dart 新手,目前陷入如何在主体中添加多个子项的问题上。现在我需要添加 4 个孩子,但我不知道该怎么办。
我试过这个:
这是我的身体:
body: Column(
children: [
LinkBox(), // Add the link box here
Expanded(child: MyHomePage()),
],
),
我需要将以下孩子添加到我的身体中:
我尝试过这样做:
body: Column(
children: [
LinkBox(), // Add the link box here
Expanded(child: MyHomePage()),
Expanded(child: ShoppingItem()),
Expanded(child: ShoppingGallery()),
],
),
也尝试这样做:
body: Column(
children: <Widget>[
LinkBox(), // Add the link box here
MyHomePage(),
ShoppingItem(),
ShoppingGallery(),
],
),
还有这个:
body: Column(
children: <Widget>[
LinkBox(), // Add the link box here
Expanded(child: MyHomePage()),
Expanded(child: ShoppingItem()),
Expanded(child: ShoppingGallery()),
],
),
这导致了很多问题,我无法在 DartPad 上运行代码。
我希望它看起来像这样:
如下:
这些是飞镖垫导致的问题:
如错误消息中所示,您的小部件
ShoppingItem
和 ShoppingGallery
具有您未提供的所需参数,这些参数是 name
、priceRange
和 rating
。如果没有必需的参数,您将无法构建 Flutter/Dart 应用程序。请阅读 https://dart.dev/language/classes 了解有关类在 dart 中如何工作的更多信息(Widget 本质上是 dart 类)