Flutter: Convert Map to Json

Issue

I am trying to convert a complex map to Json String to pass to my Firebase Realtime Database.

The Map:

_data = {
  'name':{
          'description':'This is my description',
          'price': '700'
        },
  'name2':{...}
}

What I tried:

json.encode(_data)

This gives me an error:

Converting object to an encodable object failed

Solution

I got the mistake! I was also using a for loop for putting the data in the map. However while using json.encode(for loop) doesn’t work somehow. I removed it and now it does.

Answered By – Ali Solanki

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

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