Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing only an even number of products and no products if exist only one or an odd number of products. #9

Open
NikolinNgjela opened this issue May 28, 2019 · 0 comments

Comments

@NikolinNgjela
Copy link

NikolinNgjela commented May 28, 2019

Hi @rohan20 , very useful repo about the above use case.

I’m using a similar use case only a brief change on products_list_page if I'm not wrong.
The current condition will show only an even number of products but if the category have only one product or an odd number of products like 9,11 ect… will lose one product.

I’ve add the following conditions as a workaround in order to show all products inside the condition else if (index % 2 == 0).

} else if (index % 2 == 0) {


  // if we have odd number of products 7,9,11 ect show the last one
  if (index == model.getProductsCount() - 1) {
    return ProductsListItem(
      product1: model.productsList[index],
      product2: null,
    );

  // if we have only one product
  } else if ( model.getProductsCount() == 1) {
    return ProductsListItem(
      product1: model.productsList[0],
      product2: null,
    );
  } else {
    //2nd, 4th, 6th.. index would contain nothing since this would
    //be handled by the odd indexes where the row contains 2 items
    return Container();
  }

}

Thanks for sharing the repo! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant