68 lines
1.9 KiB
Dart
68 lines
1.9 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
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 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 void uploadException({
|
|
required String message,
|
|
required String detail,
|
|
Map? data,
|
|
}) {
|
|
FlutterBugly.uploadException(message: message, detail: detail, data: data);
|
|
}
|
|
}
|