Filter data from Stream in Flutter/Dart

Viewed 922

I have a Stream which contains List of objects. i.e. List<ProductSubCategoryListModel> and ProductSubCategoryListModel contains isSelected boolean and CategoryId int.

I want to filter Stream which only has isSelected == true and get list type of List<ProductSubCategoryListModel> in return. After this need to get all the CategoryId from `List.

Here's my code.

  Future<void> fetchProducts(
  TrendingCategoriesModel categoryModel, int pageIndex) async {
_localCategoryModel = categoryModel;

//Stream I want to manipulate to get List<ProductSubCategoryListModel>
var stream = _categoryListController.stream;

var request = ProductListRequestModel();
var searchParameterModel = SearchParams();
searchParameterModel.SearchText = '';
searchParameterModel.CategoryIDs = //List<int> of CategoryIds filtered from List<ProductSubCategoryListModel>;
searchParameterModel.SubCategoryIDs = null;
searchParameterModel.AttributeIDs = null;
searchParameterModel.SubAttributeIDs = null;
searchParameterModel.StartPrice = 0;
searchParameterModel.EndPrice = null;
searchParameterModel.EndPrice = null;

request.PageIndex = pageIndex;
request.PageSize = 10;
request.SortExpression = '';
request.SortType = '';
request.IsGetFilterData = true;
request.searchParams = searchParameterModel;

if (!_productListController.isClosed) _productListController.sink.add(null);
var response =
    await _networkHandler.callAPI(NetworkUrl.PRODUCT_LIST, request);
if (response != null) {
}

}

1 Answers
Related