我是比较新的颤振和我得到以下错误信息。
错误信息:
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,
),
),
],
),
),
],
),
),
),
),
我认为这个错误是由于扩展的小部件与SizedBox冲突造成的,但我不知道解决方法是什么。我试着把扩充后的盒子改成灵活的大小箱,但没有用。任何帮助我都会感激!
发布于 2022-03-09 09:34:19
展开应该是行的子行&列
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();
}
}
);
注意:如果列表数据没有显示,您可以设置列表生成器与其他内容包装的高度。
发布于 2022-03-09 09:17:28
您只需在Row
、Column
和Flex
中使用Column
。示例:
Row(
children: [
Expanded(child: Text('Some text')),
Container(),
Expanded(child: Icon(Icons.add)),
]
);
因此,移除您的错误的Expanded
。
https://stackoverflow.com/questions/71406374
复制相似问题