IronResponse calls an JsObjectImpl object, but I cant find class docs on it

Issue

I was trying to parse the return of an IronAjax success handler and set the response to an instance of Map. It seems to not like that.

My HTML Markup is:

<iron-ajax id="myAjaxId" auto
  url="http://localhost:12345/test_server/v1/daily"
  handle-as="json"
  on-response="handleResponse" on-error="handleError"></iron-ajax>

My Dart Code is:

void handleResponse(CustomEventWrapper cew, IronRequest ir){
  print("inside handleResponse");
  var data =  ir.response;       // <-- is type JsObjectImpl
  print("data");
  print(data);
  if (data == null) return;

  print ("About to set rows");
  List<Map> rows = data.containsKey("data") ? data["data"] : [];

  print("Variables are Set locally");

  $['myDatagrid'].render();
}

@reflectable
String camelToFormal (String input){
  String out;

  RegExp regex = new RegExp("([A-Z])");
  out = input[0].toUpperCase() + input.substring(1).replaceAllMapped(regex, (Match m) => " ${m[1]}");
  return out;
}
@reflectable
void handleError(CustomEventWrapper cew, IronRequest ir){
  print("____Error:____");
  print(ir.response);
}

The Error I get is:

type 'JsObjectImpl' is not a subtype of type 'Map' of 'other'.

I wasnt sure if I need to run convert over it, even though the return type set by IronAjax was json

So, since ir.response will either be set or null, i check if it is null first. the var data line in responseHandler currently sets is, but i have also attempted to do something like: Map data = new Map.from(ir.response); which fails as well.

Even though this is said to be handled as JSON, and is returning a jslint confirmed objected, it seems to have issues to convert it to a proper map instance.

According to Polymer IronRequest at: https://elements.polymer-project.org/elements/iron-ajax?active=iron-request
it says that responseis *, the parsed response body. Am I mistaken as to how this is properly set up, or am I missing something?

Solution

You could try Object instead of map on the property and then use convertToDart. Not sure this results in a Map but worth a try I guess. See also Polymer 1.0 – iron-list – selection

Answered By – Günter Zöchbauer

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.