Flutter throws exception BoxConstraints forces an infinite width

13,578

Try adding mainAxisSize: MainAxisSize.min to your Column widget.

Share:
13,578

Related videos on Youtube

MeLean
Author by

MeLean

Nice boy.

Updated on July 23, 2022

Comments

  • MeLean
    MeLean 5 months

    I am trying to achieve a ListView with checkboxes, but i got an error that says BoxConstraints forces an infinite width. Here is my code:

    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),
                  ),
                ],
              ),
            ),
          ),
        );
      }),
    

    Here is the error:

    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)
    

Related