I have toggle issue in list view flutter

Viewed 20

I'm trying to toggle color between the elements with ListView.builder I have tried many solutions but none success

SizedBox(
                  height: context.height / 8,
                  child: ListView.builder(
                      itemBuilder: (context, index) {
                        return InkWell(
                          onTap: () =>
                              LoginHomeCubit.get(context).changeIndex(index),
/*
the function in cubit
  int currentIndex = 0;
  void changeIndex(int index) {
    emit(LoginHomeInitial());
    currentIndex = index;
    emit(ChangeIndex());
  }
*/
                          child: UserType(
                            userType: userString[index],
                            borderRadius: userBorder[index],
                            color: LoginHomeCubit.get(context).currentIndex ==
                                    index
                                ? AppColors.primaryColor
                                : Colors.white,
                          ),
                        );
                      },
                      itemCount: userString.length),
                )
0 Answers
Related