Flutter Swiper消息滚动数据为空时,快速滚动问题

211 阅读1分钟

1.问题描述

Flutter中Swiper用作消息滚动,当数据为空时,首次加载会出现快速多轮滚动问题,解决方法是添加可见控件来控制数据为空时,不显示。

List<HomeNews> news = [];
Visibility(
  visible: news.isEmpty?false:true,
  child: Swiper(
    itemCount: news.length,
    autoplay: true,
    duration: 1000,
    scrollDirection: Axis.vertical,
    itemBuilder: (BuildContext context, int index) {
      return GestureDetector(
        onTap: (){
          NavigatorUtils.push(context, NewsDetailsRouter.newsDetailsPage,replace: false,arguments: news[index].id);
        },
        child: Text(
          news[index].title.toString(),
          style: const TextStyle(
              fontSize: 12, color: Colors.white),
          maxLines: 1,
          overflow: TextOverflow.ellipsis,
        ),
      );
    },
  ),
)