Skip to content

首页的一些问题 #3

Closed
Closed

Description

@EvanEvil

发现两个问题

  1. banner每次切换的时候,回调中改变了currentIndex,调用了notifyListeners,会引起首页的重新build一次
    onIndexChanged: (index) {
    model.changeBannerIndex(index);
    },

  2. 在首页的build打印了日志,发现底部导航每次切换的时候,首页也会build一次

Activity

  1. fmtjava commented on Nov 7, 2020

    @fmtjava
    Owner

    1.banner每次切换的时候,回调中改变了currentIndex,调用了notifyListeners,首页并不会重新build一次,首页会多build一次,是因为AppBar加了actions属性导致,你可以测试一下
    2.底部导航每次切换的时候,首页也会build一次的原因是因为下标改变时,原先的代码代码使用了setState导致,这块已做了优化

  2. EvanEvil commented on Nov 17, 2020

    @EvanEvil
    Author

    1.banner每次切换的时候,回调中改变了currentIndex,调用了notifyListeners,首页并不会重新build一次,首页会多build一次,是因为AppBar加了actions属性导致,你可以测试一下
    2.底部导航每次切换的时候,首页也会build一次的原因是因为下标改变时,原先的代码代码使用了setState导致,这块已做了优化

    第二个问题已经确认了下,没问题了,第一个问题应该不是actions属性的问题,我现在是这样做的,将banner的文字部分也放到banner的itemBuilder里,onIndexChanged回调就不需要了
    Swiper(
    autoplay: true,
    pagination: SwiperPagination(alignment: Alignment.bottomRight),
    itemCount: model.bannerList.length,
    // onIndexChanged: (index) {
    // model.changeBanner(index);
    // },
    onTap: (index) {
    NavigatorManager.to(VideoDetailPage(data: model.bannerList[index].data,));
    },
    itemBuilder: (BuildContext context, int index) {
    return Stack(
    children: [
    Container(
    width: MediaQuery.of(context).size.width,
    child: CachedNetworkImage(
    imageUrl: model.bannerList[index].data.cover.feed,
    fit: BoxFit.cover,
    ),
    ),
    Positioned(
    width: MediaQuery.of(context).size.width - 30,
    bottom: 0,
    child: Container(
    padding: EdgeInsets.fromLTRB(15, 10, 0, 15),
    child: Text(
    model.bannerList[index].data.title,
    style: TextStyle(fontSize: 12, color: Colors.white),
    ),
    decoration: BoxDecoration(
    color: Colors.black12,
    borderRadius: BorderRadius.only(
    bottomLeft: Radius.circular(8),
    bottomRight: Radius.circular(8))),
    ))
    ],

            );
          },
        ),
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions