Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping out values from data Flutter

I'm having trouble extracting the values of the data received from the push notification: Message data: {default: {"event":"text","id":"23Vlj0BwSA7xKtsf4IbFCHAIsNr"}}, where I tried a lot of .map methods etc. but I always get null values. Is there an easy approach to get the data from the message.data, so I can extract the value of the event key and the id value from the id key?

like image 382
GrandMagus Avatar asked Nov 17 '25 13:11

GrandMagus


1 Answers

Can you try with the below code?

import 'dart:convert';

const rawJson =
'{"default": {"event":"text","id":"23Vlj0BwSA7xKtsf4IbFCHAIsNr"}}';

void parse() {
  final value = json.decode(rawJson);
  print(value['default']['event']);
  print(value['default']['id']);
}

Output: enter image description here

like image 190
sanjay Avatar answered Nov 19 '25 09:11

sanjay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!