ParentDataWidget 使用不正确。- 我该如何解决?

Dog*_*ick 7 mobile dart flutter

我对 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.
Run Code Online (Sandbox Code Playgroud)

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

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,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                    ],
                  ),
                ),
              ),
            ),
Run Code Online (Sandbox Code Playgroud)

我认为该错误是由于 Expanded 小部件与 SizedBox 冲突造成的,但我不确定解决方法是什么。我尝试将扩展框更改为灵活和大小框,但无济于事。我将不胜感激任何形式的帮助!

Bab*_*bul 9

Expanded 应该是 Row & Column
ListView.builder 的子级,是自动 Expanded 和可滚动的,
因此不需要通过 Expanded 包装 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,
          ),
        ),)

      ],
    );
Run Code Online (Sandbox Code Playgroud)

对于列表部分

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();
          }
        }
    );
Run Code Online (Sandbox Code Playgroud)

注意:如果列表数据未显示,您可以设置列表构建器与其他内容环绕的高度。