chopper icon indicating copy to clipboard operation
chopper copied to clipboard

Always retrieve NoSuchMethodError: The getter 'body' was called on null. Receiver: null Tried calling: body

Open korolkir opened this issue 5 years ago • 2 comments

Try to send Post request using Chopper. But I always have the following error "NoSuchMethodError: The getter 'body' was called on null. Receiver: null Tried calling: body" Service looks like:

@ChopperApi()
abstract class AppsService extends ChopperService {

  @Post(path: 'emotions/', headers: {'content-type': 'application/json'})
  Future<Response<RecordAnalysisDataModel>> uploadRecord(@Body() String body);

  static AppsService create({AuthHelper authHelper}) {
    final client = ChopperClient(
      baseUrl: 'https://${Urls.API_URL}',
      interceptors: [
        HeaderInterceptor(authHelper),
        TokenInterceptor(authHelper)
      ],
      converter: JsonToTypeConverter({
        RecordAnalysisDataModel: (json) => RecordAnalysisDataModel.fromJson(json),
      }),
      services: [
        _$AppsService(),
      ],
    );
    return _$AppsService(client);
  }
}

Call looks like:

@override
  Future<Response<RecordAnalysisDataModel>> uploadText({RecordDataModel record}) {
    var body = <String, dynamic>{
      'text': record.text,
      'recorded_at': record.recordingTime,
    };
    return _service.uploadRecord(jsonEncode(body));
  }

I double checked that I send correct string as body, but still having the issue

korolkir avatar Nov 29 '20 18:11 korolkir

I got same problem.

verowaves avatar May 31 '21 06:05 verowaves

Could you retry with 4.0.1 version?

JEuler avatar Jun 02 '21 02:06 JEuler