ReorderableListView:例外:BoxConstraints强制无限高

时间:2019-06-22 08:52:41

标签: flutter flutter-layout

TL; DR-如何在from multiprocessing import Process class A: def __init__(self): print("Starting") def login(self, auth_user, auth_pass): time.sleep(1) print(f'Username: {auth_user}\nPassword: {auth_pass}') def say_hello(self, how_many_times): for i in range(how_many_times): time.sleep(1) print(f'Times: {i}') if __name__ == '__main__': a = A() auth = { 'username': 'jnk', 'password': 'test' } p1 = Process(target=a.login(), args=(auth['username'], auth['password'],)) p2 = Process(target=a.say_hello(), args=(5,)) p1.start() p2.start() p1.join() p2.join() 中实现Starting Traceback (most recent call last): File "test.py", line 28, in <module> p1 = Process(target=a.login(), args=(auth['username'], auth['password'],)) TypeError: login() missing 2 required positional arguments: 'auth_user' and 'auth_pass'

我试图创建一个以shrinkWrap = true为父的ReorderableListView,发生了此错误。

ReoderableListView

如果使用Column<-ContainerI/flutter (32618): The following assertion was thrown during performLayout(): I/flutter (32618): BoxConstraints forces an infinite height. I/flutter (32618): The following RenderObject was being processed when the exception was fired: RenderStack#23840 relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE: I/flutter (32618): creator: Stack ← _Theatre ← Overlay-[GlobalKey#dc153 ReorderableListView overlay key] ← I/flutter (32618): ReorderableListView ← StreamBuilder<QuerySnapshot> ← Column ← Padding ← Padding ← Container ← I/flutter (32618): BoardCard ← Column ← _SingleChildViewport ← ⋯ I/flutter (32618): parentData: not positioned; offset=Offset(0.0, 0.0) (can use size) I/flutter (32618): constraints: BoxConstraints(0.0<=w<=328.0, 0.0<=h<=Infinity) I/flutter (32618): size: MISSING I/flutter (32618): alignment: AlignmentDirectional.topStart I/flutter (32618): textDirection: ltr I/flutter (32618): fit: expand I/flutter (32618): overflow: clip I/flutter (32618): This This RenderObject had the following child: I/flutter (32618): child 1: _RenderLayoutBuilder#55d3d NEEDS-LAYOUT NEEDS-PAINT ,但ListView不具有this属性,则可以很容易地解决此问题。

这是代码

shrinkWrap = true

3 个答案:

答案 0 :(得分:0)

使用Column进行列表查看并应用shrinkWrap = true

@override
  Widget build(BuildContext context) {
    final _listTitleStyle =
        TextStyle(fontSize: 20, fontWeight: FontWeight.w500);
    final _listSubTitleStyle = TextStyle(
      fontSize: 14,
      fontWeight: FontWeight.w400,
      color: Color(0xff7D7373),
    );
    return Container(
      padding: EdgeInsets.all(8),
      margin: EdgeInsets.all(8),
      child: Listview(
        shrinkWrap = true
        children: <Widget>[
          Container(
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Row(
                    textBaseline: TextBaseline.alphabetic,
                    crossAxisAlignment: CrossAxisAlignment.baseline,
                    children: <Widget>[
                      Text(
                        widget.cardTitle,
                        style: _listTitleStyle,
                      ),
                      SizedBox(
                        width: 2,
                      ),
                      Text(
                        widget.cardSubTitle,
                        style: _listSubTitleStyle,
                      ),
                    ],
                  ),
                ),
                Icon(Icons.keyboard_arrow_down),
              ],
            ),
          ),
          SizedBox(
            height: 8,
          ),
          StreamBuilder<QuerySnapshot>(
              stream: widget.query,
              builder: (context, snapshot) {
                if (!snapshot.hasData) return LinearProgressIndicator();
                return _buildList(context, snapshot.data.documents);
              }),
        ],
      ),
    );
  }

  Widget _buildList(BuildContext context, List<DocumentSnapshot> snapshot) {
    snapshot.forEach((snap) {
      print("debug 1 ${snap.data}");
      print(TodoItem.fromSnapshot(snap, snap.reference).toString());
    });
    return ReorderableListView(
      onReorder: (oldIndex, newIndex){},
      children: snapshot
          .map((data) => TodoTile(TodoItem.fromSnapshot(data, data.reference), key: UniqueKey(),))
          .toList(),
    );
  }

答案 1 :(得分:0)

我已通过用软件包flutter_reorderable_list代替ReorderableListView来解决了此问题,它接受一个子项(窗口小部件),而不像ReorderableListView接受子项(列表)

它的实现有点复杂。您可以查看example以获得对正确实施它的一些了解。

答案 2 :(得分:0)

我同意阿卜杜拉赫曼·法尤恩(Abdulrahman Falyoun)的观点。您只需要使高度动态变化并根据列表中的项目数对其进行调整即可。

 Container(
      height: (list.length * 40).toDouble(),
      padding: const EdgeInsets.all(10),
      child: ReorderableListView(
        children: list.map((item) {
          return getItem(item);
        }).toList(),
        onReorder: _onReorder,
      ),
    )

或者如果它在列中,则用Expanded()

换行