ListTile within a Card causing RenderBox was not laid

670 views Asked by At

I am trying to put ListTile within a Card but I am getting a renderbox error

════════ 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())))
      ]),
1

There are 1 answers

3
Md. Yeasin Sheikh On

The issue is coming from ListTile's trailing, you can wrap Text with SizedBox(width:x). Issue occurs on large text.

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

Also, you can create custom ListTile while its default behavior. Here is a sample

Does it solve your issue?