在运行代码时,我得到一个错误,显示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
你有一个无限高的Scaffold
。这是因为SomrasMain.dart
中的Home
部件将HomeScreen
置于SingleChildScrollView
中。
解决这个问题最简单的方法是从HomeScreen
中删除Scaffold
。您不需要一个,因为整个小部件包含在Home
中,它已经提供了一个Scaffold
。
将你的FutureBuilder和settopList方法都包装为Expanded