【发布时间】:2021-10-04 03:35:00
【问题描述】:
在运行代码时,我收到一个错误,显示不正确使用 ParentDataWidget 和 RenderCustomMultiChildLayoutBox 对象在布局期间被赋予了无限大小。
@override
Widget build(BuildContext context) {
return Scaffold(
body: _column,
);
}
get _column {
return Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
_setTitleText(Constant.shuffle_drinks, 8),
_setTop10List(
list: randomCocktailList,
height: 150,
width: 300,
axis: Axis.horizontal,
listHeight: 150,
textSize: 14,
flag: false),
Container(
margin: EdgeInsets.only(left: 16, right: 16),
child: _ingredientGrid,
),
_setTitleText(Constant.latest_drink, 8),
_setTop10List(
list: latestCocktailList,
height: 150,
width: 300,
axis: Axis.horizontal,
listHeight: 150,
textSize: 14,
flag: false),
_setTitleText("Popular Drinks", 8),
Column(
mainAxisSize: MainAxisSize.min,
children: [
_setTop10List(
list: popularCocktailList,
height: 150,
width: MediaQuery.of(context).size.width,
axis: Axis.vertical,
listHeight: double.maxFinite,
textSize: 14,
flag: true),
],
)
],
)};
更多代码:
Widget _setTop10List(
{Future<List<Cocktail>> list,
double height,
double width,
Axis axis,
double listHeight,
double textSize,
bool flag}) {
if (axis == Axis.vertical) {
return Column(
children: [
Utils.getFutureBuilder(
list: list,
height: height,
width: width,
axis: axis,
listHeight: listHeight,
textSize: textSize,
flag: flag)
],
);
} else {
return Container(
height: listHeight,
child: Utils.getFutureBuilder(
list: list,
height: height,
width: width,
axis: axis,
listHeight: listHeight,
textSize: textSize,
flag: flag),
);
}
}
Widget _setTitleText(String title, double top) {
return Container(
alignment: Alignment.topLeft,
margin: EdgeInsets.only(left: 16, top: top),
child: Flexible(
// alignment: Alignment.topLeft,
flex: 1,
child: Text(
title,
style: TextStyle(
color: Colors.black87,
fontFamily: "Poppins",
fontSize: 18,
letterSpacing: 1,
fontWeight: FontWeight.w600),
),
),
);
}
}
我得到的错误是:
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
The relevant error-causing widget was
Scaffold
【问题讨论】:
-
尝试在 Expanded() 或 Flexible() 中包装其中一列?
-
@JaffaKetchup 试过但没有帮助
-
可以加
_setTop10List和_setTitleText -
请提供完整的代码,以便我们重现问题
-
@MohammadHosein 这是完整的代码.. github.com/yadavmangesh/somras-cocktail-app/blob/master/lib/…
标签: flutter flutter-layout flutter-web