在运行代码时,我收到一个错误,显示在布局期间错误使用 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
答案 0 :(得分:1)
你有一个无限高的 Scaffold
。这是因为 Home
中的 SomrasMain.dart
小部件将 HomeScreen
放在 SingleChildScrollView
中。
解决此问题的最简单方法是从 Scaffold
中删除 HomeScreen
。无论如何你都不需要,因为整个小部件都包含在 Home
中,它已经提供了一个 Scaffold
。
答案 1 :(得分:0)
用 Expanded 包裹您的 FutureBuilder 并用 Expanded 包裹您的 settopList 方法