代码之家  ›  专栏  ›  技术社区  ›  MeLean

颤振控制异常框约束强制无限宽

  •  0
  • MeLean  · 技术社区  · 6 年前

    我试图用复选框实现一个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)
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   MeLean    6 年前

    mainAxisSize: MainAxisSize.min Column