knoxpo / dart_algolia

[Unofficial] Algolia is a pure dart SDK, wrapped around Algolia REST API for easy implementation for your Flutter or Dart projects.
Other
117 stars 112 forks source link

No object returned in Flutter Web Release #75

Closed ZacharyBohn closed 2 years ago

ZacharyBohn commented 2 years ago

Dart version: [ eg: 2.14.2 ] Flutter version: [ eg: 2.5.1 ]

Bug Description Flutter web release mode always errors out instead of returning an Algolia snapshot. I have a fix at the bottom. It should at least help point in the right direction.

This is only in release mode and not debug mode. An error is printed to the browser console: NoSuchMethodError: method not found: 'h' on null (Note that flutter web will replace method names so 'h' doesn't really mean anything.)

Reproduction Steps to reproduce the behavior:

  1. Setup an Algolia index
  2. Build any flutter project for web (in release mode).
  3. Try to query any objects from Algolia.

Expected behavior When query() is called, then an Algolia snapshot is returned with correct hits.

Desktop (please complete the following information):

Additional context / Fix I was able to fix the issue by replacing lib/src/algolia.dart: line 111

    return response;

Right now it is:

    return json.decode(response.body);

I'm pretty sure that the return type should be http.Response, however json.decode is returning dynamic. I'm not 100% sure why it works in debug mode and not release, or why this fixes it. Please let me know if you need any more info.

ZacharyBohn commented 2 years ago

I just saw that https://github.com/knoxpo/dart_algolia/pull/73 already fixes this.