错误使用 ParentDataWidget。 - 我该如何解决?

Incorrect use of ParentDataWidget. - How do I fix this?

我是 Flutter 的新手,收到以下错误消息。

错误信息:

The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.

Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a SizedBox widget.

以下是我认为错误的代码:

Material(
              elevation: 2,
              color: Colors.white70,
              child:
              Padding(
                padding: EdgeInsets.symmetric(
                  horizontal: size.width * 0.05,
                  vertical: size.height * 0.02,
                ),
                child: SizedBox(
                  height: size.height * 0.4,
                  width: size.width,
                  child: Column(
                    children: <Widget>[
                      _orders
                          ? StreamBuilder(
                              stream: FirebaseFirestore.instance
                                  .collection('VendorOrders')
                                  .doc(_uid)
                                  .collection('CurrentOrders')
                                  .orderBy('orderTime', descending: true)
                                  .snapshots(),
                              builder: (context,
                                  AsyncSnapshot<QuerySnapshot> orderSnapshot) {
                                if (orderSnapshot.connectionState ==
                                    ConnectionState.waiting) {
                                  return Container(
                                    alignment: Alignment.center,
                                    child: Center(
                                      child: CircularProgressIndicator(
                                        backgroundColor: colorTeal,
                                        strokeWidth: 1,
                                      ),
                                    ),
                                  );
                                } else {
                                  //error is likely from here
                                  return Expanded( 
                                      child: ListView.builder(
                                          itemCount:
                                              orderSnapshot.data.docs.length,
                                          itemBuilder: (context, index) {
                                            DocumentSnapshot order =
                                                orderSnapshot.data.docs[index];
                                            if (current(order)) {
                                              return VendorOrderDetailCard(
                                                  doc: order);
                                            } else {
                                              return Container();
                                            }
                                          }
                                          )
                                  );
                                }
                              })
                          : Expanded(
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Text(
                                    'There are no ongoing orders',
                                    textAlign: TextAlign.center,
                                    style: TextStyle(
                                      color: colorDarkBlue,
                                      fontFamily: 'Montserrat',
                                      fontSize: 16.0,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                    ],
                  ),
                ),
              ),
            ),

我认为错误是由于 Expanded 小部件与 SizedBox 冲突造成的,但我不确定解决方法是什么。 我试图将 expanded 更改为 flexible 和 sizedbox 但无济于事。 如果能提供任何帮助,我将不胜感激!

您可以在 RowColumnFlex 中使用 Expanded。示例:

Row(
  children: [
     Expanded(child: Text('Some text')),
     Container(),
     Expanded(child: Icon(Icons.add)),
  ]
);

所以删除你错位的Expanded

Expanded 应该是行和列的子项
ListView.builder 是自动展开和滚动的,
所以不需要用展开来包装 ListView.builder。您可以通过以下代码片段尝试您的代码的两个部分。

return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Expanded(child:  Text(
          'There are no ongoing orders hfdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh',
          textAlign: TextAlign.center,
          style: TextStyle(
            color: Colors.amber,
            fontFamily: 'Montserrat',
            fontSize: 16.0,
            fontWeight: FontWeight.bold,
          ),
        ),)

      ],
    );

列表部分

return ListView.builder(
        itemCount:
        orderSnapshot.data.docs.length,
        itemBuilder: (context, index) {
          DocumentSnapshot order =
          orderSnapshot.data.docs[index];
          if (current(order)) {
            return VendorOrderDetailCard(
                doc: order);
          } else {
            return Container();
          }
        }
    );

注意:如果列表数据未显示,您可以设置用其他内容包裹的列表生成器的高度。