更新睡眠报告提示样式,更新ios蓝牙开关判定
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'package:img_picker/img_picker.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
@@ -32,7 +33,7 @@ class DailyLogUtils {
|
||||
|
||||
// 写入 warning 日志
|
||||
static Future<void> writeWarning(String content) async {
|
||||
print("[dailylog-->waring] $content]");
|
||||
print("[dailylog-->waring] $content]");
|
||||
await _writeLogWithLevel('WARNING', content);
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ class DailyLogUtils {
|
||||
}
|
||||
|
||||
// 读取当天日志
|
||||
static Future<String> readTodayLog() async {
|
||||
static Future<String> readTodayLog() async {
|
||||
final file = await _getLogFile();
|
||||
return await file.readAsString();
|
||||
}
|
||||
@@ -93,4 +94,51 @@ class DailyLogUtils {
|
||||
|
||||
return logFiles;
|
||||
}
|
||||
|
||||
static Future<String> readLogsByDateRange(
|
||||
DateTime fromDate, DateTime toDate) async {
|
||||
try {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
final dateFormat = DateFormat('yyyy-MM-dd');
|
||||
String combinedLogs = '';
|
||||
|
||||
// 遍历从 fromDate 到 toDate 的日期
|
||||
for (DateTime date = fromDate;
|
||||
!date.isAfter(toDate);
|
||||
date = date.add(Duration(days: 1))) {
|
||||
final dateStr = dateFormat.format(date); // 格式化日期
|
||||
final file = File('${dir.path}/$dateStr.log'); // 日志文件路径
|
||||
|
||||
if (await file.exists()) {
|
||||
final logContent = await file.readAsString();
|
||||
combinedLogs += '日志日期: $dateStr\n$logContent\n\n'; // 合并日志内容
|
||||
}
|
||||
}
|
||||
|
||||
if (combinedLogs.isNotEmpty) {
|
||||
return combinedLogs; // 返回合并后的日志
|
||||
} else {
|
||||
return '该时间段内没有日志记录'; // 如果没有日志
|
||||
}
|
||||
} catch (e) {
|
||||
return '读取日志失败: $e';
|
||||
}
|
||||
}
|
||||
|
||||
// 添加分享功能
|
||||
// static Future<void> exportLog(DateTime date) async {
|
||||
// try {
|
||||
// final dir = await getApplicationDocumentsDirectory();
|
||||
// final dateStr = DateFormat('yyyy-MM-dd').format(date);
|
||||
// final file = File('${dir.path}/$dateStr.log');
|
||||
// if (await file.exists()) {
|
||||
// await Share.shareXFiles(
|
||||
// [XFile(file.path)],
|
||||
// text: '应用日志 $dateStr',
|
||||
// );
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print('导出日志失败: $e');
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user