如何在一个body中添加多个子元素

问题描述 投票:0回答:1

我是 Dart 新手,目前陷入如何在主体中添加多个子项的问题上。现在我需要添加 4 个孩子,但我不知道该怎么办。

我试过这个:

这是我的身体:

body: Column(
    children: [
      LinkBox(), // Add the link box here
    Expanded(child: MyHomePage()),
    ],
  ),

我需要将以下孩子添加到我的身体中:

  1. 链接框()
  2. 我的主页()
  3. 购物项目()
  4. 购物廊()

我尝试过这样做:

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 上运行代码。

我希望它看起来像这样:

图1

如下:

图2

这些是飞镖垫导致的问题:

第一个问题
第二个问题
第三个问题

flutter dart children scaffold
1个回答
0
投票

如错误消息中所示,您的小部件

ShoppingItem
ShoppingGallery
具有您未提供的所需参数,这些参数是
name
priceRange
rating
。如果没有必需的参数,您将无法构建 Flutter/Dart 应用程序。请阅读 https://dart.dev/language/classes 了解有关类在 dart 中如何工作的更多信息(Widget 本质上是 dart 类)

© www.soinside.com 2019 - 2025. All rights reserved.