refactor: 优化日志输出,仅在调试模式下启用

- 为所有 print 语句添加 kDebugMode 检查
- 更新 KRLogUtil 工具类,Release 模式下禁用日志输出
- 优化 18 个文件中的 335+ 条日志语句
- 提升 Release 版本性能并增强安全性

(cherry picked from commit 301f1510ba81fe94fb08e013ca80b3ca708a2e15)
This commit is contained in:
2025-11-01 05:15:34 -07:00
committed by speakeloudest
parent b3ee1cc6dc
commit 4c5763647d
18 changed files with 665 additions and 232 deletions
+22 -7
View File
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:country_flags/country_flags.dart';
import 'package:flutter/foundation.dart';
class KRCountryFlag extends StatelessWidget {
final String countryCode;
@@ -38,17 +39,29 @@ class KRCountryFlag extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 🔍 调试日志
print('🏳️ KRCountryFlag.build 被调用');
print(' - 原始 countryCode: "$countryCode"');
print(' - countryCode.isEmpty: ${countryCode.isEmpty}');
print(' - countryCode.length: ${countryCode.length}');
if (kDebugMode) {
print('🏳️ KRCountryFlag.build 被调用');
}
if (kDebugMode) {
print(' - 原始 countryCode: "$countryCode"');
}
if (kDebugMode) {
print(' - countryCode.isEmpty: ${countryCode.isEmpty}');
}
if (kDebugMode) {
print(' - countryCode.length: ${countryCode.length}');
}
final processedCode = _getCountryCode(countryCode);
print(' - 处理后 code: "$processedCode"');
if (kDebugMode) {
print(' - 处理后 code: "$processedCode"');
}
// 如果国家代码为空,显示占位符
if (countryCode.isEmpty) {
print(' ❌ 国家代码为空,显示占位符');
if (kDebugMode) {
print(' ❌ 国家代码为空,显示占位符');
}
return Container(
width: width ?? 50.w,
height: height ?? 50.w,
@@ -65,7 +78,9 @@ class KRCountryFlag extends StatelessWidget {
final double actualWidth = width ?? 50.w;
final double actualHeight = maintainSize ? actualWidth : (height ?? 50.w);
print(' ✅ 尝试加载国旗: $processedCode');
if (kDebugMode) {
print(' ✅ 尝试加载国旗: $processedCode');
}
Widget flagWidget = CountryFlag.fromCountryCode(
processedCode,