Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get size of object in bytes especially list<dynamic> or map<string,dynamic>?

Tags:

flutter

dart

For some reason, I am looking for an approach to get the size-of an object. My target object is list or map<string,dynamic>. I am looking through the document, there is sizeOf() but doesn't have any arguments more.

Is there something wrong?

like image 586
TeeTracker Avatar asked Sep 14 '25 16:09

TeeTracker


1 Answers

This should help. But I'm not sure it is working in your case. Please test it well.

import 'dart:convert';


final json = yourObject.toJson();
final jsonString = jsonEncode(json);
final jsonSizeInBytes = utf8.encode(jsonString).length;
print('JSON size: $jsonSizeInBytes bytes');
like image 98
IvanPavliuk Avatar answered Sep 17 '25 05:09

IvanPavliuk