94 lines
3.1 KiB
Dart
94 lines
3.1 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_bugly/flutter_bugly.dart';
|
|
import 'package:star_lock/app_settings/app_settings.dart';
|
|
import 'package:star_lock/flavors.dart';
|
|
import 'package:star_lock/login/login/entity/LoginData.dart';
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
///
|
|
/// 错误日志监控
|
|
///
|
|
///
|
|
class BuglyTool {
|
|
static int time = 0;
|
|
|
|
static Future<void> init() async {
|
|
if (F.isProductionEnv) {
|
|
//生产
|
|
await FlutterBugly.init(
|
|
androidAppId: '5729fb97dc',
|
|
iOSAppId: '33c4430cce',
|
|
);
|
|
} else {
|
|
//测试
|
|
await FlutterBugly.init(
|
|
androidAppId: '5729fb97dc',
|
|
iOSAppId: '33c4430cce',
|
|
);
|
|
}
|
|
|
|
//关联用户 id
|
|
final LoginData? loginData = await Storage.getLoginData();
|
|
setUserId(loginData?.userid);
|
|
|
|
//错误日志监控
|
|
// FlutterError.onError = (FlutterErrorDetails details) async {
|
|
// AppLog.log('error:${details.exception.toString()}',
|
|
// stackTrace: details.stack, error: true);
|
|
// FlutterBugly.uploadException(
|
|
// message: details.exception.toString(),
|
|
// detail: details.stack.toString());
|
|
// Zone.current.handleUncaughtError(
|
|
// details.exception, details.stack ?? StackTrace.empty);
|
|
// };
|
|
|
|
//错误日志监控
|
|
PlatformDispatcher.instance.onError = (Object error, StackTrace stack) {
|
|
AppLog.log('error:$error', stackTrace: stack, error: true);
|
|
FlutterBugly.uploadException(
|
|
message: error.toString(), detail: stack.toString());
|
|
return true;
|
|
};
|
|
}
|
|
|
|
//关联 userid
|
|
static void setUserId(int? userId) {
|
|
FlutterBugly.setUserId(userId?.toString() ?? '');
|
|
}
|
|
|
|
static String uploadStr = '';
|
|
static Future<void> uploadException({
|
|
required String message,
|
|
required String detail,
|
|
required bool upload,
|
|
String eventStr = '开门事件',
|
|
bool begin = false,
|
|
Map? data,
|
|
}) async {
|
|
String getMessage =
|
|
'${(await Storage.getMobile())!.isNotEmpty ? (await Storage.getMobile()) : (await Storage.getEmail())}+$time --- message:$message detail:$detail';
|
|
if (begin == true) {
|
|
// 开始
|
|
uploadStr = '';
|
|
} else {
|
|
uploadStr = '$uploadStr \n<----------->\n $getMessage';
|
|
}
|
|
|
|
if (upload) {
|
|
// AppLog.log('message:${(await Storage.getMobile())!.isNotEmpty ? (await Storage.getMobile()) : (await Storage.getEmail())}+$time --- 开门事件 detail:$uploadStr');
|
|
// FlutterBugly.uploadException(message: '${(await Storage.getMobile())!.isNotEmpty ? (await Storage.getMobile()) : (await Storage.getEmail())}+$time --- 开门事件', detail: uploadStr, data: data);
|
|
|
|
BuglyTool.uploadExceptionWithEvent(eventStr: eventStr, detail: uploadStr);
|
|
}
|
|
}
|
|
|
|
static Future<void> uploadExceptionWithEvent({
|
|
required String eventStr,
|
|
required String detail,
|
|
}) async {
|
|
// FlutterBugly.uploadException(message: '${(await Storage.getMobile())!.isNotEmpty ? (await Storage.getMobile()) : (await Storage.getEmail())}+${time == 0 ? DateTime.now().millisecondsSinceEpoch : 0}--- $eventStr', detail: detail);
|
|
}
|
|
}
|