0

我正在尝试显示AnimatedListof ExpansionTiles/ListTilesin Flutter,这就是发生的情况: 在此处输入图像描述

这是我的代码:

Expanded (
    child: Column(
        children: [
            Expanded(
                flex: 10,
                child: Padding(
                padding: EdgeInsets.symmetric(vertical: 5),
                child: Text(
                        "Results found: ${widget.guests.length}",
                        textScaleFactor: useMobileLayout ? 1 : 1.3,
                        style: TextStyle(
                        fontWeight: FontWeight.bold,
                        ),
                    ),
                ),
            ),
            Expanded(
                flex: 90,
                child: Scrollbar(
                child: buildList(),
                ),
            ),
        ],
    ),
) 

Widget buildList(BoxConstraints constraints) {
      return AnimatedList(
        key: _animatedListKey,
        initialItemCount: 10,
        shrinkWrap: true,
        physics: const AlwaysScrollableScrollPhysics(),
        itemBuilder: (BuildContext context, int index, Animation animation) {
          return buildAnimatedItem(
              widget.guests[index], index, animation);
        },
      );
}

Widget buildAnimatedItem(Guest guest, int index, Animation animation) {
    return SizeTransition(
      sizeFactor: animation.drive(
        Tween(begin: 0.0, end: 0.1),
      ),
      child: buildItem(guest, index: index),
    );
}

Widget buildItem(Guest guest, {int index}) {
   return GuestRow();
}

我认为也许 Expanded 会导致 AnimatedList 出现填充问题,但我不确定。

你能告诉这里发生了什么吗?

4

1 回答 1

0

问题是我将as设置sizeFactorSizeTransition

animation.drive(
    Tween(begin: 0.0, end: 0.1),
  ),

它应该在哪里

animation.drive(
    Tween(begin: 0.0, end: 1.0), // <-- changed 0.1 to 1.0
  ),
于 2019-08-26T07:17:57.243 回答