RenderFlex错误未解决的shrinkWrap, SizedBox或Expanded



我目前正在构建一个AlertDialog来显示对特定菜肴的评论。我得到以下错误:

在performLayout()过程中抛出以下断言:RenderShrinkWrappingViewport不支持返回intrinsic维度。更新了RenderFlex#d31e4所需的布局信息relayoutBoundary=up7 NEEDS-LAYOUT NEEDS-PAINT计算语义。包:颤振/src/渲染对象。dart':断言失败:行3175 pos 12: '!_needsLayout '

我使用的代码如下

return AlertDialog(
title: Center(child: Text("Αξιολογήσεις")),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Divider(height: 5, color: Colors.blueGrey,),
StreamBuilder<List<Review>>(
stream: DatabaseService(collectionName: 'ratings').reviews,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
final reviews = snapshot.data!;
return ListView(
shrinkWrap: true,
children: reviews.map((review) => Review(rating: review.rating, username: review.timestamp, review: review.review, timestamp: review.timestamp,)).toList(),
);
},
),
],
),
);

查看小部件:

class Review extends StatelessWidget{
final String username;
final double rating;
final String review;
final String timestamp;
const Review({super.key, required this.rating, required this.username, required this.review, required this.timestamp});
@override
Widget build(BuildContext context){
return ListTile(
title: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
CircleAvatar(
backgroundImage: AssetImage('assets/logo_circle_white.png'),
radius: 24.0,
),
SizedBox(width: 8,),
Expanded(child: Text("Ο χρήστης $username αναφέρει:",style: TextStyle(fontSize: 16, fontStyle: FontStyle.italic),))
]),
],
),
subtitle: Column(
children: [
Text('Η κριτική υποβλήθηκε στις: $timestamp'),
Divider()
],
),
trailing: Text('$rating'),
);
}
}

最后是数据库函数

//get item stream
Stream<List<Review>> get reviews{
return itemCollection.snapshots().map(_getRatingsFromSnapshot);
}
List<Review> _getRatingsFromSnapshot(QuerySnapshot snapshot){ // _ makes it private
try {
return snapshot.docs.map((doc) { // map cycles through document list
return Review( //return a review for each one
username: doc.get('username') ?? 'anonymous',
rating: doc.get('rating').toDouble() ?? 0.0,
review: doc.get('review') ?? '-',
timestamp: doc.get('timestamp') ?? '00:00 00/00/00',
);
}).toList(); // convert iterable to list
}
catch(e){
print(e.toString());
return [];
}
}

我尝试将listview放置在Expanded小部件中,SizedBox具有高度,包裹在SingleChildScrollViewer中,Streambuilder相同。这些解决方案并没有解决我的问题。有什么问题吗?

代替AlertDialog试试Dialog

return Dialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Center(child: Text("Αξιολογήσεις")),
Divider(height: 5, color: Colors.blueGrey,),
StreamBuilder<List<Review>>(
stream: DatabaseService(collectionName: 'ratings').reviews,
builder: (context, snapshot) {
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
final reviews = snapshot.data!;
return ListView(
shrinkWrap: true,
children: reviews.map((review) => Review(rating: review.rating, username: review.timestamp, review: review.review, timestamp: review.timestamp,)).toList(),
);
},
),
],
),
);

相关内容

  • 没有找到相关文章

最新更新