出错场景
如果我们在使用约束时没有正确的传入宽高,比如以下代码
ConstrainedBox(
/// 设置最小高度为150, 最大高度为100.
constraints: BoxConstraints(minHeight: 150,maxHeight: 100),
child: Container(
color: Colors.red,
child: Center(
child: Text('呵呵'),
),
),
),
运行会报以下错误
======== Exception caught by widgets library =======================================================
The following assertion was thrown building AsyncTaskPage(dirty, dependencies: [MediaQuery, _ViewScope], state: _AsyncTaskPageState#e16b3):
BoxConstraints has non-normalized height constraints.
The offending constraints were: BoxConstraints(0.

文章讲述了在Flutter中使用ConstrainedBox时遇到的错误,即BoxConstraint的非正常化高度约束。作者分析了错误原因,指出当设置的最小高度大于最大高度时会导致错误,并给出了正确的代码示例。
最低0.47元/天 解锁文章
2833

被折叠的 条评论
为什么被折叠?



