algolia / algoliasearch-helper-flutter

⚡️ Building block to create instant-search applications with Flutter
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/flutter/
Other
21 stars 14 forks source link

V1.0.0 TypeError: null: type 'Null' is not a subtype of type 'String' #133

Closed Patrick386 closed 2 months ago

Patrick386 commented 2 months ago

After version 1.0.0 of algolia_helper_flutter, I noticed that the hit data includes '_highlightResult', which does not match the user's model data. This results in a TypeError.

  Stream<_HitsPage> get _searchPage =>
       hitsSearcher.responses.map(_HitsPage.fromResponse);

....
class _HitsPage {
  const _HitsPage(this.items, this.pageKey, this.nbPages, this.nextPageKey);
  final List<ItemData> items;
  final int pageKey;
  final int? nextPageKey;
  final int nbPages;

  factory _HitsPage.fromResponse(SearchResponse response) {
    logger.info('>>>> data hits:${response.hits} / nbPages:${response.nbPages}');

   // TypeError : null: type 'Null' is not a subtype of type 'String'
    final List<ItemData> items =  response.hits.map(ItemData.fromJson).toList(); 

   logger.info('>>>> items hits:${items.length}');

    final bool isLastPage = response.page >= response.nbPages;
    final int? nextPageKey = isLastPage ? null : response.page + 1;

    return _HitsPage(items, response.page, response.nbPages, nextPageKey);
  }
}

Hit data

   INFO: >>>> data hits:[Hit{ json: 
    {objectID: sw7YaNb0YKwmvxJKdKxw, 
    _highlightResult: {name: {value: Rolex stock 22, matchLevel: none, matchedWords: []}, 
                                   mainCategory: {value: StockOffer, matchLevel: none, matchedWords: []}}, 
   ............. published: true, createdAt: 2023-12-11T23:45:31.509, updatedAt: 2024-04-25 22:26:44.829}}] 

ℹ️   INFO: >>>Has Error:TypeError: null: type 'Null' is not a subtype of type 'String'
Patrick386 commented 2 months ago

I found the root cause of the issue. It was not related to '_highlightResult' but rather a problem with the data itself. Now that it's been resolved, I will close this.