Search code examples
flutterhttpflutter-http

Flutter: Convert Map to Json


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.