gpt4 book ai didi

Flutter 抛出异常 BoxConstraints 强制无限宽度

转载 作者:IT王子 更新时间:2023-10-29 06:41:32 35 4
gpt4 key购买 nike

我正在尝试实现带有复选框的 ListView,但我收到一条错误消息,提示 BoxConstraints 强制无限宽度。这是我的代码:

body: ListView.builder(itemCount: _items.length,
itemBuilder: (BuildContext context, int index) {
bool _isLastClickedIndex = index == _lastClickedPosition;
return Container(
child: Card(
margin: EdgeInsets.all(8.0),
color: index % 2 == 0 ? Colors.grey : Colors.white,
child: Center(
child: Column(
children: <Widget>[
CheckboxListTile(
title: Text('Title Text'),
subtitle: Text('Subtitle text'),
controlAffinity: ListTileControlAffinity.leading,
value: _isLastClickedIndex,
onChanged: (bool value) {
_onCheckBoxChanged(value, index);
},
secondary: Icon(Icons.people),
),
],
),
),
),
);
}),

这里是错误:

I/flutter (27333): The following assertion was thrown during performLayout():
I/flutter (27333): BoxConstraints forces an infinite width.
I/flutter (27333): These invalid constraints were provided to RenderConstrainedBox's layout() function by the following
I/flutter (27333): function, which probably computed the invalid constraints in question:
I/flutter (27333): _RenderListTile._layoutBox (package:flutter/src/material/list_tile.dart:726:9)
I/flutter (27333): The offending constraints were:
I/flutter (27333): BoxConstraints(w=Infinity, 0.0<=h<=Infinity)
I/flutter (27333):
I/flutter (27333): When the exception was thrown, this was the stack:
I/flutter (27333): #0 BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError (package:flutter/src/rendering/box.dart:468:9)
I/flutter (27333): #1 BoxConstraints.debugAssertIsValid.<anonymous closure> (package:flutter/src/rendering/box.dart:509:21)

最佳答案

尝试将 mainAxisSize: MainAxisSize.min 添加到您的 Column 小部件。

关于Flutter 抛出异常 BoxConstraints 强制无限宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51312847/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com