flutterchina / azlistview

A Flutter sticky headers & index ListView. Flutter 城市列表、联系人列表,索引&悬停。
BSD 3-Clause "New" or "Revised" License
1.14k stars 280 forks source link

Disable susItem float #63

Open kightsonsanom opened 3 years ago

kightsonsanom commented 3 years ago

Hello, first of all great library! very customizable. I have a question regarding sticky susItems. Is it possible to disable their stickiness? I would prefer them to stay in one place. I saw solutions with using Offstage widget for providing headers in the itemBuilder callback but I wonder if it is possible to user sysItemBuilder with the same effect.

This is what I have: sticky

And the code

return AzListView(
      padding: EdgeInsets.zero,
      data: state.universities!,
      itemCount: state.universities!.length,
      itemBuilder: (BuildContext context, int index) {
        UniversityItem model = state.universities![index];
        return getListItem(context, model);
      },
      susItemBuilder: (BuildContext context, int index) {
        UniversityItem model = state.universities![index];
        String location = model.location;
        return getSusItem(context, location);
      },
      indexBarData: SuspensionUtil.getTagIndexList(state.universities),
      indexBarOptions: const IndexBarOptions(
        needRebuild: true,
        selectTextStyle: TextStyle(
            fontSize: 12,
            color: AppColors.brandGreen,
            fontWeight: FontWeight.w500),
        selectItemDecoration: BoxDecoration(),
      ),
    );

This is what I want: nonsticky

Current code to achieve this:

    return AzListView(
      padding: EdgeInsets.zero,
      data: state.universities!,
      itemCount: state.universities!.length,
      itemBuilder: (BuildContext context, int index) {
        final UniversityItem model = state.universities![index];

        return Column(
          children: [
            Offstage(
              offstage: !model.isShowSuspension,
              child: _buildUniversityHeader(context, model.location),
            ),
            _buildUniversityItem(context, model),
          ],
        );
      },
      indexBarData: SuspensionUtil.getTagIndexList(state.universities),
      indexBarOptions: const IndexBarOptions(
        needRebuild: true,
        selectTextStyle: TextStyle(
            fontSize: 12,
            color: AppColors.brandGreen,
            fontWeight: FontWeight.w500),
        selectItemDecoration: BoxDecoration(),
      ),
    );
Sky24n commented 3 years ago

Only in this way,Refer to this example contacts_list_page

garv-shah commented 1 year ago

I'm having the same issue but I want it to be only sticky, and it seems to be doing both as shown in the gif. My current code is as follows:

AzListView(
  data: displayedUserList,
  physics: const AlwaysScrollableScrollPhysics(),
  itemCount: displayedUserList.length,
  itemBuilder: (BuildContext context, int index) {
    UserModel model = displayedUserList[index];
    return getListItem(context, model);
  },
  itemScrollController: itemScrollController,
  susItemBuilder: (BuildContext context, int index) {
    UserModel model = displayedUserList[index];
    return getSusItem(context, model.getSuspensionTag());
  },
  indexBarOptions: const IndexBarOptions(
    needRebuild: true,
    selectTextStyle: TextStyle(
        fontSize: 12,
        color: Colors.white,
        fontWeight: FontWeight.w500),
    selectItemDecoration: BoxDecoration(
        shape: BoxShape.circle, color: Color(0xFF333333)),
    indexHintWidth: 96,
    indexHintHeight: 97,
    indexHintDecoration: BoxDecoration(
      image: DecorationImage(
        image: AssetImage('assets/images/ic_index_bar_bubble_white.png'),
        fit: BoxFit.contain,
      ),
    ),
    indexHintAlignment: Alignment.centerRight,
    indexHintTextStyle:
        TextStyle(fontSize: 24.0, color: Colors.black87),
    indexHintOffset: Offset(-30, 0),
  ),
)

Any ideas?