0

我正在尝试将 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())))
      ]),
4

1 回答 1

1

问题来自ListTile's trailing,你可以TextSizedBox(width:x). 大文本出现问题。

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

此外,您可以在其默认行为时创建自定义 ListTile。这是一个示例

它解决了你的问题吗?

于 2021-09-24T10:05:51.197 回答