Using js-interop how can I convert javascript Array and Object to native dart Map.

Issue

Is it possible to convert a javascript object or array back to native dart Map and/or List? I’m trying to get a manifest file returned from javascript as Object and want to convert it to a Dart Map object.

Solution

Many changes in API was done by this year, following code is Alexandre Ardhuin’s answer adapted to latest (#30104) Dart Sdk

import "dart:convert";
import "dart:js" as js;

convert( js.JsObject object )
{
  return JSON.decode( js.context['JSON'].callMethod("stringify", [ object ] ) );
}

Answered By – MDerks

Answer Checked By – Marie Seifert (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *