61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter_bugly_plugin/flutter_bugly_plugin.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 FlutterBuglyPlugin.init(
|
|
appIdAndroid: '73c99cca00',
|
|
appIdiOS: 'b25632a54f',
|
|
);
|
|
} else {
|
|
//测试
|
|
await FlutterBuglyPlugin.init(
|
|
appIdAndroid: '02fb541c1c',
|
|
appIdiOS: '618ab9feeb',
|
|
);
|
|
}
|
|
|
|
//关联用户 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);
|
|
FlutterBuglyPlugin.reportException(
|
|
exceptionName: details.exception.toString(),
|
|
reason: 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);
|
|
FlutterBuglyPlugin.reportException(
|
|
exceptionName: error.toString(), reason: stack.toString());
|
|
return true;
|
|
};
|
|
}
|
|
|
|
//关联 userid
|
|
static void setUserId(int? userId) {
|
|
FlutterBuglyPlugin.setUserIdentifier(
|
|
userIdentifier: (userId ?? 0).toString());
|
|
}
|
|
}
|