File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -125,11 +125,32 @@ class HiveChatController
125125 }
126126}
127127
128- // ignore: unintended_html_in_doc_comment
129- /// Efficient type conversion for Map<dynamic, dynamic> to Map<String, dynamic>
128+ /// Recursively converts a map with dynamic keys and values to a map with String keys.
129+ /// It's optimized to avoid creating new maps if no conversion is needed.
130130Map <String , dynamic > _convertMap (dynamic map) {
131131 if (map is Map <String , dynamic >) {
132- return map;
132+ Map <String , dynamic >? newMap;
133+ for (final entry in map.entries) {
134+ final value = entry.value;
135+ if (value is Map ) {
136+ final convertedValue = _convertMap (value);
137+ if (convertedValue != value) {
138+ newMap ?? = Map <String , dynamic >.of (map);
139+ newMap[entry.key] = convertedValue;
140+ }
141+ }
142+ }
143+ return newMap ?? map;
133144 }
134- return Map <String , dynamic >.from (map);
145+
146+ final convertedMap = Map <String , dynamic >.from (map as Map );
147+
148+ for (final key in convertedMap.keys) {
149+ final value = convertedMap[key];
150+ if (value is Map ) {
151+ convertedMap[key] = _convertMap (value);
152+ }
153+ }
154+
155+ return convertedMap;
135156}
You can’t perform that action at this time.
0 commit comments