fix:解决冲突

This commit is contained in:
2026-06-29 21:46:55 +08:00
4 changed files with 81 additions and 18 deletions

View File

@@ -108,7 +108,7 @@ class HttpUtil {
// 没有转换器时尝试直接返回(可能不安全,建议提供转换器)
return response.data;
} catch (e) {
rethrow;
throw Exception(_handleError(e));
}
}
@@ -171,7 +171,7 @@ class HttpUtil {
);
// 错误处理
void _handleError(dynamic error) {
String _handleError(dynamic error) {
String errorMessage = '未知错误';
if (error is DioException) {
switch (error.type) {
@@ -218,7 +218,7 @@ class HttpUtil {
}
logger.e(errorMessage);
// showErrorToast(errorMessage);
return errorMessage;
}
String _getHttpErrorMessage(int statusCode) {

View File

@@ -1,12 +1,34 @@
import 'package:logger/logger.dart';
import 'dart:convert';
import 'dart:io';
// 全局日志实例,在整个项目中共享
final Logger logger = Logger(
printer: PrettyPrinter(
methodCount: 1,
colors: true,
dateTimeFormat: DateTimeFormat.dateAndTime,
),
// 可选:配置输出到文件(需配合文件操作库)
// output: FileOutput(file: File('logs/app.log')),
);
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:path_provider/path_provider.dart';
// 全局日志实例
late Logger logger;
// 初始化日志
Future<void> initLogger() async {
if (kIsWeb) {
logger = Logger(
printer: SimplePrinter(printTime: true),
output: ConsoleOutput(),
);
} else {
final directory = await getExternalStorageDirectory();
final logFile = File('${directory?.path}/logs/app.log');
// 确保文件存在(会自动创建)
await logFile.create(recursive: true);
logger = Logger(
filter: ProductionFilter(),
printer: SimplePrinter(printTime: true),
output: MultiOutput([
ConsoleOutput(),
FileOutput(file: logFile, overrideExisting: true, encoding: utf8),
]),
);
}
}