AnimatedBuilder被多次调用

时间:2020-04-13 15:57:10

标签: flutter

我有以下代码。 newList包含从snapshot获取的数据。

Widget _buildListChild(AsyncSnapshot<ModelHolidays> snapshot) {
    var data = snapshot.data.d;
    newList = json.decode(data.getholidaylist);

    return ListView.builder(
        padding: EdgeInsets.only(top: size.getSizePx(10)),
        scrollDirection: Axis.vertical,
        shrinkWrap: true,
        physics: const BouncingScrollPhysics(),
        itemCount: newList.length,
        controller: scrollContainer,
        itemBuilder: (context, index) {
          final int count = 1; 
          final Animation<double> animation =
              Tween<double>(begin: -1.0, end: 1.0).animate(
            CurvedAnimation(
              parent: holidayAnimationController,
              curve: Interval((1 / count) * index * 2, 1.0,
                  curve: Curves.fastOutSlowIn),
            ),
          );

          holidayAnimationController.forward();

          return AnimatedBuilder(
            animation: holidayAnimationController,
            builder: (BuildContext context, Widget child) {
              print("######################");
              print("Animated Builder");
              print("######################");
              return Container();

            },
          );
        });
  }

问题

newList仅从API返回一条记录。但是AnimatedBuilder似乎有问题。 builder的{​​{1}}内的打印语句实际上被打印了70多次。这正常吗?如果没有,怎么解决呢?我在颤抖方面还很陌生。

谢谢

0 个答案:

没有答案