ListTile在Card中导致RenderBox没有铺设



我试图把ListTile内卡,但我得到一个渲染框错误

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderPhysicalShape#c872a relayoutBoundary=up7
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1930 pos 12: 'hasSize'
The relevant error-causing widget was
Card
lib/…/task/make_offer.dart:100

ListView(children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 10.0,
),
child: TextFormField(
controller: _offerController,
textInputAction: TextInputAction.next,
// textCapitalization: TextCapitalization.words,
// maxLength: 40,
decoration: const InputDecoration(
hintText: '5-9999',
prefixIcon: Icon(Icons.attach_money_rounded),
labelText: 'Your Offer',
),
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.singleLineFormatter
],
onChanged: (offerAmount) => _offerAmount = offerAmount as int,
),
),
Card(
child: ListTile(
leading: Text('Fee'),
trailing: Text(_offerController.toString())))
]),

问题来自ListTiletrailing,您可以用SizedBox(width:x)包装Text。大文本出现问题。

Card(
child: ListTile(
leading: Text('Fee'),
trailing: SizedBox(
width: 40,
child: Text(
"_offerController.toString()xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsd",
/// you can add others property here
),
),
),
)

同样,您可以在其默认行为时创建自定义ListTile。下面是一个示例

它能解决你的问题吗?

最新更新