From 99ed31f99270e03eaa06c3eb4f09c92db184971f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=9A=E5=81=9A=E9=A5=AD=E7=9A=84=E4=BA=8C=E5=93=88?= Date: Mon, 17 Mar 2025 23:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=AA=8C=E8=AF=81=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/config/cof.dart | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/config/cof.dart b/lib/config/cof.dart index 30f235f..4264c0f 100644 --- a/lib/config/cof.dart +++ b/lib/config/cof.dart @@ -146,7 +146,13 @@ class ConfigManager { for (final item in list) { buffer.write('$prefix- '); if (item is Map) { - _writeMap(item.cast(), buffer, indent + 1); + if (item.isEmpty) { + buffer.writeln('{}'); + } else { + buffer.writeln(); + // 注意这里使用了正确的缩进级别 + _writeMapInList(item.cast(), buffer, indent + 1); + } } else if (item is List) { _writeList(item, buffer, indent + 1); } else { @@ -155,6 +161,25 @@ class ConfigManager { } } + /// 专门用于处理列表中的Map项,确保正确缩进 + void _writeMapInList( + Map map, StringBuffer buffer, int indent) { + final prefix = ' ' * indent; + + map.forEach((key, value) { + buffer.write('$prefix$key: '); + + if (value is Map) { + buffer.writeln(); + _writeMap(value, buffer, indent + 1); + } else if (value is List) { + _writeList(value, buffer, indent + 1); + } else { + buffer.writeln(_formatValue(value)); + } + }); + } + /// 格式值处理 String _formatValue(dynamic value) { if (value is String) return '"$value"';